Documentation ¶
Index ¶
- func ReadConfigFile(filepath string, optFns ...func(*ConfigFileOptions) error) (interface{}, error)
- func ReadIniFile(filepath string) (*ini.File, error)
- func ReadYamlFile(filepath string, optFns ...func(*ConfigFileOptions) error) (interface{}, error)
- type ConfigFileOptions
- type ConfigFileOptionsFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadConfigFile ¶ added in v0.0.4
func ReadConfigFile(filepath string, optFns ...func(*ConfigFileOptions) error) (interface{}, error)
Read the file given by filepath. Viper instance is returned if optClass is not provided. Otherwise Unmarshalling will be performed. If optClass is provided, Unmarshalling will be performed and the class will be updated. No object will be returned. optClass is expected to be a pointer to a struct.
For example:
type Config struct { Name string } var config Config err := ReadConfigFile("config.yaml", WithClass(&config)) if err != nil { doSomethingWithError(err) }
func ReadIniFile ¶
Read the file given by filepath as an INI file
func ReadYamlFile ¶
func ReadYamlFile(filepath string, optFns ...func(*ConfigFileOptions) error) (interface{}, error)
Read the file given by filepath as a YAML file
Types ¶
type ConfigFileOptions ¶ added in v0.0.4
type ConfigFileOptions struct { Type string Class interface{} }
Supported options for reading config files
type ConfigFileOptionsFunc ¶ added in v0.0.4
type ConfigFileOptionsFunc func(f *ConfigFileOptions) error
ConfigFileOptionsFunc is a type alias for ConfigFileOptions functional option
func WithCFOClass ¶ added in v0.0.4
func WithCFOClass(class interface{}) ConfigFileOptionsFunc
WithCFOClass is a helper function to construct functional options that sets class for unmarshalling on config's ConfigFileOptions.
func WithCFOType ¶ added in v0.0.4
func WithCFOType(fileType string) ConfigFileOptionsFunc
WithCFOType is a helper function to construct functional options that sets config file type on config's ConfigFileOptions.