Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseConfig ¶ added in v1.1.0
func ParseConfig(loader ConfigLoader, target interface{}) error
ParseConfig uses the specified loader to extract configuration into the target
func ParseCustomFlag ¶ added in v1.2.0
ParseCustomFlag will schedule to load the YAML file from the default path or using the path specified using custom command line flag (flagName) when Load() is called
Types ¶
type ConfigLoader ¶ added in v1.1.0
type ConfigLoader interface {
Parse(path string, target interface{}) error
ParseCustomFlag(defaultPath string, flagName string, v interface{})
Path() string
Load() error
}
ConfigLoader should load a file at the given path into the target interface
type ConfigLoaderMock ¶ added in v1.1.0
type ConfigLoaderMock struct {
// ParseFunc mocks the Parse function.
ParseFunc func(path string, target interface{}) error
// PathFunc mocks the Path function.
PathFunc func() string
}
ConfigLoaderMock is a mock implementation of ConfigLoader.
func TestSomethingThatUsesConfigLoader(t *testing.T) {
// make and configure a mocked ConfigLoader
mockedConfigLoader := &ConfigLoaderMock{
ParseFunc: func(path string, target interface{}) error {
panic("TODO: mock out the Parse function")
},
PathFunc: func() string {
panic("TODO: mock out the Path function")
},
}
// TODO: use mockedConfigLoader in code that requires ConfigLoader
}
func (*ConfigLoaderMock) Parse ¶ added in v1.1.0
func (mock *ConfigLoaderMock) Parse(path string, target interface{}) error
Parse calls ParseFunc.
func (*ConfigLoaderMock) Path ¶ added in v1.1.0
func (mock *ConfigLoaderMock) Path() string
Path calls PathFunc.
type YamlLoader ¶ added in v1.1.0
type YamlLoader struct {
ConfigPath string
}
YamlLoader implements the loader interface to load YAML files
func (*YamlLoader) Parse ¶ added in v1.1.0
func (l *YamlLoader) Parse(path string, target interface{}) error
Parse loads the .yml file from Loader.ConfigPath if set, defaultPath as a fallback. Adheres to the LoaderBlueprint interface.
func (*YamlLoader) Path ¶ added in v1.1.0
func (l *YamlLoader) Path() string
Path returns the config path for the yaml file returns ConfigPath if specified on the struct, else attempts to parse from -c flag