Documentation ¶
Overview ¶
Package conf is a package that specializes in parsing out environment variables using structs with annotated tags to control how it is done.
Index ¶
- Constants
- Variables
- func BinaryUnmarshaler(field reflect.Value) (b encoding.BinaryUnmarshaler)
- func BindCLI(cmd *cobra.Command, v *viper.Viper, spec interface{}, prefix ...string) error
- func CollectParamsFromEnv(appTitle string, spec interface{}, skipDefaults bool, prefix ...string) (map[string]string, error)
- func EnvNames(spec interface{}, prefix ...string) ([]string, error)
- func EnvNamesNoDefaults(spec interface{}, prefix ...string) ([]string, error)
- func EnvReport(spec interface{}, prefix ...string) (map[string]string, error)
- func EnvToMap(spec interface{}, prefix ...string) (map[string]string, error)
- func EnvVar(key string) (string, error)
- func EnvVarOptional(key string) string
- func EnvVarStrict(key string) (string, error)
- func PStoreKey(field Field, appTitle, env string) string
- func ParamEnvField(appTitle, env string, field Field) (string, string, error)
- func ParamNames(appTitle string, spec interface{}, skipDefaults bool, prefix ...string) ([]string, error)
- func ProcessCLI(cmd *cobra.Command, v *viper.Viper, spec interface{}, prefix ...string) error
- func ProcessEnv(spec interface{}, prefix ...string) error
- func ProcessField(value string, field reflect.Value) error
- func TextUnmarshaler(field reflect.Value) (t encoding.TextUnmarshaler)
- type Config
- func (c *Config) CollectParamsFromEnv(appTitle string) (map[string]string, error)
- func (c *Config) EnvNames() ([]string, error)
- func (c *Config) EnvReport() (map[string]string, error)
- func (c *Config) EnvToMap() (map[string]string, error)
- func (c *Config) GetPrefix() string
- func (c *Config) IsDefaultsExcluded() bool
- func (c *Config) IsPrefixEnabled() bool
- func (c *Config) MarkDefaultsAsExcluded()
- func (c *Config) MarkDefaultsAsIncluded()
- func (c *Config) ParamNames(appTitle string) ([]string, error)
- func (c *Config) ProcessCLI(cmd *cobra.Command, v *viper.Viper) error
- func (c *Config) ProcessEnv() error
- func (c *Config) SetExcludeDefaults(value bool)
- func (c *Config) SetPrefix(prefix string)
- type Decoder
- type Field
- func (f Field) BindName() string
- func (f Field) CLIFlag() string
- func (f Field) CLIShortFlag() string
- func (f Field) CLIUsage() string
- func (f Field) DefaultValue() string
- func (f Field) EnvVariable() string
- func (f Field) IsCLI() bool
- func (f Field) IsDefault() bool
- func (f Field) IsGlobalParamStore() bool
- func (f Field) IsParamStore() bool
- func (f Field) IsPersistentFlag() bool
- func (f Field) IsRequired() bool
- func (f Field) ParamStoreKey() string
- type Setter
- type Tag
Constants ¶
const ( AWSLambdaFunctionNameVar = "AWS_LAMBDA_FUNCTION_NAME" AWSProfile = "AWS_PROFILE" AWSRegion = "AWS_REGION" AppName = "APP_NAME" GlobalParamStoreKey = "global" )
Variables ¶
var (
InvalidSpecFailure = failure.Config("specification must be a struct pointer")
)
Functions ¶
func BinaryUnmarshaler ¶
func BinaryUnmarshaler(field reflect.Value) (b encoding.BinaryUnmarshaler)
func CollectParamsFromEnv ¶ added in v0.3.0
func EnvNamesNoDefaults ¶ added in v0.3.0
func EnvVar ¶
EnvVar ensures the variable you are looking for is set. If you don't care about that use EnvVarOptional instead
func EnvVarOptional ¶
EnvVarOptional is a wrapper around os.Getenv with the intent that by using this method you are declaring in code that you don't care about empty env vars. This is better than just using os.Getenv because that intent is not conveyed. So this simple wrapper has the purpose of reveal intent and not wrapping for the sake of wrapping
func EnvVarStrict ¶
EnvVarStrict ensures the variable is set and not empty
func ParamEnvField ¶ added in v0.3.0
func ParamNames ¶ added in v0.3.0
func ProcessCLI ¶
func ProcessEnv ¶
func TextUnmarshaler ¶
func TextUnmarshaler(field reflect.Value) (t encoding.TextUnmarshaler)
Types ¶
type Config ¶
func (*Config) CollectParamsFromEnv ¶ added in v0.3.0
func (*Config) IsDefaultsExcluded ¶ added in v0.3.0
func (*Config) IsPrefixEnabled ¶ added in v0.3.0
func (*Config) MarkDefaultsAsExcluded ¶ added in v0.3.0
func (c *Config) MarkDefaultsAsExcluded()
func (*Config) MarkDefaultsAsIncluded ¶ added in v0.3.0
func (c *Config) MarkDefaultsAsIncluded()
func (*Config) ParamNames ¶ added in v0.3.0
func (*Config) ProcessEnv ¶
func (*Config) SetExcludeDefaults ¶ added in v0.3.0
type Decoder ¶
Decoder has the same semantics as Setter, but takes higher precedence. It is provided for historical compatibility.
func DecoderFrom ¶
type Field ¶
type Field struct { StructName string Name string Prefix string EnvVar string ReflectValue reflect.Value ReflectTag reflect.StructTag Tag Tag // contains filtered or unexported fields }
Field holds information about the current configuration variable
func (Field) CLIShortFlag ¶
func (Field) DefaultValue ¶
func (Field) EnvVariable ¶
func (Field) IsGlobalParamStore ¶
func (Field) IsParamStore ¶
func (Field) IsPersistentFlag ¶
func (Field) IsRequired ¶
func (Field) ParamStoreKey ¶
type Setter ¶
Setter is implemented by types can self-deserialize values. Any type that implements flag.Value also implements Setter.
func SetterFrom ¶
type Tag ¶
type Tag struct { EnvVar string CLIFlag string CLIShort string CLIUsage string PStoreVar string IsPStoreGlobal bool Default string IsCLIPFlag bool IsDefault bool NoCLIBind bool NoPrint bool NoPrefix bool Required bool Mask bool }
Tag represents the annotated tag `conf` used to control how we will parse that property.