Documentation ¶
Index ¶
- func Load(appCfgs ...interface{}) error
- func LoadOrDie(appCfgs ...interface{})
- func Show() error
- func ShowOrDie()
- type ConfigExtNotFoundErr
- type GoConfig
- func DisableStdFlags() *GoConfig
- func FieldHelp(fieldName, helpTxt string) *GoConfig
- func FieldTag(fieldName, tagName, helpTxt string) *GoConfig
- func New() *GoConfig
- func NewWithPrefix(prefix string) *GoConfig
- func RegisterLoadUnloader(loadUnloader *LoadUnloader) *GoConfig
- func SetConfigPath(pth string) *GoConfig
- func Version(s string) *GoConfig
- func With(with ...string) *GoConfig
- func WithFlagOptions(o flg.Options) *GoConfig
- func WithShowOptions(o render.Options) *GoConfig
- func (g *GoConfig) DisableStdFlags() *GoConfig
- func (g *GoConfig) FShowValues(w io.Writer) error
- func (g *GoConfig) FieldHelp(fieldName, helpTxt string) *GoConfig
- func (g *GoConfig) FieldTag(fieldName, tagName, helpTxt string) *GoConfig
- func (g *GoConfig) Load(appCfgs ...interface{}) error
- func (g *GoConfig) LoadOrDie(appCfg ...interface{})
- func (g *GoConfig) RegisterLoadUnloader(loadUnloader *LoadUnloader) *GoConfig
- func (g *GoConfig) SetConfigPath(pth string) *GoConfig
- func (g *GoConfig) ShowValues() error
- func (g *GoConfig) Version(v string) *GoConfig
- func (g *GoConfig) With(newWith ...string) *GoConfig
- func (g *GoConfig) WithFlagOptions(o flg.Options) *GoConfig
- func (g *GoConfig) WithShowOptions(o render.Options) *GoConfig
- type LoadUnloader
- type LoaderNotFoundErr
- type UnloaderNotFoundErr
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
func Load(appCfgs ...interface{}) error
Load is a package wrapper around *GoConfig.Load().
Types ¶
type ConfigExtNotFoundErr ¶ added in v0.3.0
type ConfigExtNotFoundErr struct {
// contains filtered or unexported fields
}
func (ConfigExtNotFoundErr) Error ¶ added in v0.3.0
func (ce ConfigExtNotFoundErr) Error() string
type GoConfig ¶ added in v0.3.1
type GoConfig struct {
// contains filtered or unexported fields
}
func DisableStdFlags ¶ added in v0.5.0
func DisableStdFlags() *GoConfig
DisableStdFlags is a package wrapper around *GoConfig.DisableFlagHelp().
func NewWithPrefix ¶ added in v0.6.0
NewWithPrefix creates a new config with a global prefix for loaders.
func RegisterLoadUnloader ¶ added in v0.3.0
func RegisterLoadUnloader(loadUnloader *LoadUnloader) *GoConfig
RegisterLoadUnloader is a package wrapper around *GoConfig.RegisterLoadUnloader().
func SetConfigPath ¶ added in v0.5.0
SetConfigPath is a package wrapper around *GoConfig.SetConfigPath().
func WithFlagOptions ¶ added in v0.3.2
func WithShowOptions ¶ added in v0.3.0
func (*GoConfig) DisableStdFlags ¶ added in v0.5.0
DisableStdFlags will disable standard CLI options such as --gen.
Note: This does not disable flag usage. To disable flags entirely call "With" providing the config types you wish to include.
func (*GoConfig) FieldHelp ¶ added in v0.3.3
FieldHelp allows adding a struct field help tag at runtime. Field names are dot "." separated values when referring to struct fields in struct fields.
Field names are validated when "Load" is called.
func (*GoConfig) FieldTag ¶ added in v0.3.3
FieldTag allows for runtime modification of struct field tags. Field names are dot "." separated values when referring to struct fields in struct fields.
Field names are validated when "Load" is called.
func (*GoConfig) Load ¶ added in v0.3.1
Load handles: - basic validation - flag pre-loading for handling standard flags and customizing the help screen - final config load - post load validation by:
- enforcing "validate" struct field tag directives TODO
- calling the custom Validate method (if implemented) TODO
func (*GoConfig) LoadOrDie ¶ added in v0.3.1
func (g *GoConfig) LoadOrDie(appCfg ...interface{})
LoadOrDie calls Load and prints an error message and exits if there is an error.
func (*GoConfig) RegisterLoadUnloader ¶ added in v0.3.1
func (g *GoConfig) RegisterLoadUnloader(loadUnloader *LoadUnloader) *GoConfig
RegisterLoadUnloader registers a LoadUnloader.
The name is the name referenced when using With if specifying a custom subset of loaders.
TODO: Change this behavior to include the custom loader unless "With" is exercised and the loader is not included. When using "With" you must also include the name of the custom registered loader or it will not be used.
Using a standard loader name replaces that standard loader. If, for example "toml" is the provided custom name then the custom "toml" implementation will be used instead of the standard one. Note that custom implementations of standard file loaders will need to specify the desired fileExt file extensions.
FileExts is optional and if specified indicates the configuration is found at a file with the provided file extension. At least one FileExts is required for loading from a configuration file. Multiple file extensions can be registered. Space characters and leading periods (".") are trimmed. Therefore you could also provide ".yaml" or "yaml". It doesn't matter.
Because of its special nature, overriding "flag" is not allowed. Attempting to override "flag" will panic. Flags can be disabled by taking advantage of the "With" method and omitting "flag".
Not providing name or LoadUnloader will panic.
func (*GoConfig) SetConfigPath ¶ added in v0.5.0
SetConfigPath can be used to set the config path in a manner other than through the standard "--config,-c" standard flag.
This can be useful when the user: - Wishes to set a default config flag value. - Wishes to set a config path while having standard flags disabled.
Note: The --config,-c flag value will override this value unless standard flags are disabled.
func (*GoConfig) ShowValues ¶ added in v0.3.1
ShowValues writes the values to os.Stderr.
func (*GoConfig) Version ¶ added in v0.3.1
Version sets the application version. If a version is provided then the user can specify the --version flag to show the version. Otherwise the version flag is not seen on the help screen.
func (*GoConfig) With ¶ added in v0.3.1
With sets which configuration loaders are enabled. Order matters. Configuration is loaded in the same order as the new specified "with" list.
Values can be any of: "env", "toml", "yaml", "json", "flag" or names of custom loaders registered with RegisterLoadUnloader.
If a loader name does not exist then With panics. Custom LoadUnloaders must be registered before calling With.
func (*GoConfig) WithFlagOptions ¶ added in v0.3.2
type LoadUnloader ¶ added in v0.3.0
type LoadUnloader struct { Name string // FileExts tells go-config what extensions to look for when matching a config file // name to a LoadUnloader. No file extensions means the config can be loaded by some // other means such as environment variables loading from the environment or from a server // like etcd, consul or vault. FileExts []string // Loader is required. Loader load.Loader // Unloader is not required; if not present then config templates will not be generatable for it. Unloader load.Unloader }
type LoaderNotFoundErr ¶ added in v0.3.0
type LoaderNotFoundErr struct {
// contains filtered or unexported fields
}
func (LoaderNotFoundErr) Error ¶ added in v0.3.0
func (ue LoaderNotFoundErr) Error() string
type UnloaderNotFoundErr ¶ added in v0.3.0
type UnloaderNotFoundErr struct {
// contains filtered or unexported fields
}
func (UnloaderNotFoundErr) Error ¶ added in v0.3.0
func (ue UnloaderNotFoundErr) Error() string