Documentation ¶
Overview ¶
Package config implements configuration components of gogitsu lib.
Package config implements configuration components of gogitsu lib.
Package config implements configuration components of gogitsu lib.
Index ¶
- Constants
- type Configurator
- func (c *Configurator) FUsage(w io.Writer, cfg interface{}, headerText *string, usageFuncs ...func()) func()
- func (c *Configurator) FileName() string
- func (c *Configurator) GetDescription(cfg interface{}, headerText *string) (string, error)
- func (c *Configurator) Load(cfg interface{}) error
- func (c *Configurator) LoadFromFile(path string, cfg interface{}) error
- func (c *Configurator) Parser() Parser
- func (c *Configurator) Usage(cfg interface{}, headerText *string, usageFuncs ...func()) func()
- func (c *Configurator) WithEnvPrefix(envPrefix string) *Configurator
- func (c *Configurator) WithFileNamePrefix(prefix string) *Configurator
- func (c *Configurator) WithFormat(format string) *Configurator
- func (c *Configurator) WithParser(parser Parser) *Configurator
- func (c *Configurator) WithPath(path string) *Configurator
- type ENVParser
- type JSONParser
- type Parser
- type Setter
- type TOMLParser
- type YAMLParser
Constants ¶
const ( // TagEnv is the Name of the environment variable or a list of names TagEnv = "env" // TagEnvLayout is the Value parsing layout (for types like time.Time) TagEnvLayout = "env-layout" // TagEnvDefault is the Default value TagEnvDefault = "env-default" // TagEnvSeparator is the Custom list and map separator TagEnvSeparator = "env-separator" // TagEnvDescription is the Environment variable description TagEnvDescription = "env-description" // TagEnvRequired is the Flag to mark a field as required TagEnvRequired = "env-required" )
const (
// DefaultSeparator is a default list and map separator character
DefaultSeparator = ","
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configurator ¶
type Configurator struct {
// contains filtered or unexported fields
}
Configurator is the main struct to access configuration functionalities.
func NewConfigurator ¶
func NewConfigurator() *Configurator
NewConfigurator returns a new Configurator instance. Here we not set a parser.
func NewConfiguratorFor ¶
func NewConfiguratorFor(format string) *Configurator
NewConfiguratorFor returns a new Configurator with a configured parser for the input format.
func (*Configurator) FUsage ¶
func (c *Configurator) FUsage(w io.Writer, cfg interface{}, headerText *string, usageFuncs ...func()) func()
FUsage prints configuration help into the custom output. Other usage instructions can be wrapped in and executed before this usage function
func (*Configurator) FileName ¶
func (c *Configurator) FileName() string
FileName returns the configuration filename.
func (*Configurator) GetDescription ¶
func (c *Configurator) GetDescription(cfg interface{}, headerText *string) (string, error)
GetDescription returns a description of environment variables. You can provide a custom header text.
func (*Configurator) Load ¶
func (c *Configurator) Load(cfg interface{}) error
Load reads configuration from default file into the cfg structure.
func (*Configurator) LoadFromFile ¶
func (c *Configurator) LoadFromFile(path string, cfg interface{}) error
LoadFromFile reads configuration from the specified file into the cfg structure.
func (*Configurator) Parser ¶
func (c *Configurator) Parser() Parser
Parser returns the internal parser instance.
func (*Configurator) Usage ¶
func (c *Configurator) Usage(cfg interface{}, headerText *string, usageFuncs ...func()) func()
Usage returns a configuration usage help. Other usage instructions can be wrapped in and executed before this usage function. The default output is STDERR.
func (*Configurator) WithEnvPrefix ¶
func (c *Configurator) WithEnvPrefix(envPrefix string) *Configurator
WithEnvPrefix configure the env vars prefix.
func (*Configurator) WithFileNamePrefix ¶
func (c *Configurator) WithFileNamePrefix(prefix string) *Configurator
WithFileNamePrefix .
func (*Configurator) WithFormat ¶
func (c *Configurator) WithFormat(format string) *Configurator
WithFormat configure the internal Parser according to the input format.
func (*Configurator) WithParser ¶
func (c *Configurator) WithParser(parser Parser) *Configurator
WithParser configure the internal Parser.
func (*Configurator) WithPath ¶
func (c *Configurator) WithPath(path string) *Configurator
WithPath adds a path into the serach paths.
type ENVParser ¶
type ENVParser struct{}
ENVParser will parse env from env file. It does not fill the struct, but set variables into the env.
type Parser ¶
Parser is the interface to define parsing functionality to read from a reader and parse values into a struct. A concrete Parser will read from the input "r" reader and parse values into the "s" struct using a concrete decoder.
type Setter ¶
Setter is an interface for a custom value setter.
To implement a custom value setter you need to add a SetValue function to your type that will receive a string raw value:
type MyField string func (f *MyField) SetValue(s string) error { if s == "" { return fmt.Errorf("field value can't be empty") } *f = MyField("my field is: " + s) return nil }