Documentation ¶
Index ¶
- func ConfigFileEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, df DecoderFactory, params Params[T]) (*dials.Dials[T], error)
- func ConfigFileEnvFlagDecoderFactoryParams[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, df DecoderFactoryWithParams[T], params Params[T]) (*dials.Dials[T], error)
- func CueConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
- func DecoderFromExtension(path string) dials.Decoder
- func DecoderFromExtensionWithParams[T any](path string, p Params[T]) dials.Decoder
- func FileExtensionDecoderConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
- func JSONConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
- func TOMLConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
- func YAMLConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
- type ConfigWithConfigPath
- type DecoderFactory
- type DecoderFactoryWithParams
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigFileEnvFlag ¶
func ConfigFileEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, df DecoderFactory, params Params[T]) (*dials.Dials[T], error)
ConfigFileEnvFlag takes advantage of the ConfigWithConfigPath cfg to indicate what file to read and uses the passed decoder. Configuration values provided by the returned Dials are the result of stacking the sources in the following order:
- configuration file
- environment variables
- flags it registers with the standard library flags package
The contents of cfg for the defaults cfg.ConfigPath() is evaluated on the stacked config with the file-contents omitted (using a "blank" source)
func ConfigFileEnvFlagDecoderFactoryParams ¶ added in v0.14.0
func ConfigFileEnvFlagDecoderFactoryParams[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, df DecoderFactoryWithParams[T], params Params[T]) (*dials.Dials[T], error)
ConfigFileEnvFlagDecoderFactoryParams takes advantage of the ConfigWithConfigPath cfg to indicate what file to read and uses the passed decoder. Configuration values provided by the returned Dials are the result of stacking the sources in the following order:
- configuration file
- environment variables
- flags it registers with the standard library flags package
The contents of cfg for the defaults cfg.ConfigPath() is evaluated on the stacked config with the file-contents omitted (using a "blank" source) It differs from ConfigFileEnvFlag by the signature of the decoder factory, (which requires a params struct in this function)
func CueConfigEnvFlag ¶ added in v0.9.3
func CueConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
CueConfigEnvFlag takes advantage of the ConfigWithConfigPath cfg, thinly wraping ConfigFileEnvFlag with the decoder statically set to Cue.
func DecoderFromExtension ¶ added in v0.10.0
DecoderFromExtension is a DecoderFactory that returns an appropriate decoder based on the extension of the filename or nil if there is not an appropriate mapping.
func DecoderFromExtensionWithParams ¶ added in v0.14.0
DecoderFromExtension is a DecoderFactory that returns an appropriate decoder based on the extension of the filename or nil if there is not an appropriate mapping.
func FileExtensionDecoderConfigEnvFlag ¶
func FileExtensionDecoderConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
FileExtensionDecoderConfigEnvFlag takes advantage of the ConfigWithConfigPath cfg and thinly wraps ConfigFileEnvFlag and and thinly wraps ConfigFileEnvFlag choosing the dials.Decoder used when handling the file contents based on the file extension (from the limited set of JSON, Cue, YAML and TOML).
func JSONConfigEnvFlag ¶
func JSONConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
JSONConfigEnvFlag takes advantage of the ConfigWithConfigPath cfg, thinly wraping ConfigFileEnvFlag with the decoder statically set to JSON.
func TOMLConfigEnvFlag ¶
func TOMLConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
TOMLConfigEnvFlag takes advantage of the ConfigWithConfigPath cfg, thinly wraping ConfigFileEnvFlag with the decoder statically set to TOML.
func YAMLConfigEnvFlag ¶
func YAMLConfigEnvFlag[T any, TP ConfigWithConfigPath[T]](ctx context.Context, cfg TP, params Params[T]) (*dials.Dials[T], error)
YAMLConfigEnvFlag takes advantage of the ConfigWithConfigPath cfg, thinly wraping ConfigFileEnvFlag with the decoder statically set to YAML.
Types ¶
type ConfigWithConfigPath ¶
type ConfigWithConfigPath[T any] interface { *T // ConfigPath implementations should return the configuration file to // be read as the first return-value, and true, or an empty string and // false. ConfigPath() (string, bool) }
ConfigWithConfigPath is an interface config struct that supplies a ConfigPath() method to indicate which file to read as the config file once populated.
type DecoderFactory ¶
DecoderFactory should return the appropriate decoder based on the config file path that is passed as the string argument to DecoderFactory
type DecoderFactoryWithParams ¶ added in v0.14.0
DecoderFactoryWithParams should return the appropriate decoder based on the config file path that is passed as the string argument to DecoderFactory Params may provide useful context/arguments
type Params ¶
type Params[T any] struct { // OnWatchedError registers a callback to record any errors encountered // while stacking or verifying a new version of a configuration (if // file-watching is enabled) OnWatchedError dials.WatchedErrorHandler[T] // OnNewConfig registers a callback to record new config versions // reported while watching the config OnNewConfig dials.NewConfigHandler[T] // WatchConfigFile allows one to watch the config file by using the // watching file source. WatchConfigFile bool // FlagConfig sets the flag NameConfig FlagConfig *flag.NameConfig // FlagSource one to use a different flag source instead of the // default commandline-source from the flag package. // This explicitly supports use with the pflag package's source.Set type. FlagSource dials.Source // DisableAutoSetToSlice allows you to set whether sets (map[string]struct{}) // should be automatically converted to slices ([]string) so they can be // naturally parsed by JSON, YAML, or TOML parsers. This is named as a // negation so AutoSetToSlice is enabled by default. DisableAutoSetToSlice bool // DialsTagNameDecoder indicates the naming scheme in use for // dials tags in this struct (copied from field-names if unspecified). // This is only useful if using a FileFieldNameEncoder (below) // // In many cases, the default of caseconversion.DecodeGoCamelCase // should work. This field exists to allow for other naming schemes. // (e.g. SCREAMING_SNAKE_CASE). // // See the caseconversion package for available decoders. // Note that this does not affect the flags or environment-variable // naming. To manipulate flag naming, see `WithFlagConfig`. DialsTagNameDecoder caseconversion.DecodeCasingFunc // FileFieldNameEncoder allows one to manipulate the casing of the keys // in the configuration file. See the DialsTagNameDecoder field for // controlling how dials splits field-names into "words". // Fields that lack a `dials` tag's formatting. If the `dials` tag is unspecified, the struct // field's name will be used. The encoder argument should indicate the format // that dials should expect to find in the file. // // For instance if you leave the `dials` tag unspecified and want a // field named `SecretValues` in your configuration to map to a value // in your config named "secret-values" you can set: // Params { // DialsTagNameDecoder: caseconversion.DecodeGoCamelCase, // FileFieldNameEncoder: caseconversion.EncodeKebabCase, // } // Note that this does not affect the flags or environment variable // naming. To manipulate flag naming, see [Params.FlagConfig]. FileFieldNameEncoder caseconversion.EncodeCasingFunc // FlattenAnonymousFields inserts the AnonymousFlattenMangler into the // chain so decoders that do not handle anonymous fields never see such // things. // (Currently only affects the yaml decoder) FlattenAnonymousFields bool }
Params defines options for the configuration functions within this package All fields can be left empty, zero values will be replaced with sane defaults. As such, it is expected that struct-literals of this type will be sparsely populated in almost all cases.