configuration: Index | Files

package configuration

import ""

Package configuration provides ability to initialize your custom configuration struct from: flags, environment variables, `default` tag, files (json, yaml)


Package Files

configurator.go defaultProvider.go envProvider.go fieldSetter.go fileProvider.go flagProvider.go helpers.go interfaces.go tagGetters.go

func New Uses

func New(
    cfgPtr interface{},
    providers ...Provider,
) (configurator, error)

New creates a new instance of the configurator. 'gLoggingEnabled' and 'gFailIfCannotSet' both are set to 'true' by default default logger function is set to `log.Printf`

func NewDefaultProvider Uses

func NewDefaultProvider() defaultProvider

NewDefaultProvider creates new provider which sets values from `default` tag

func NewEnvProvider Uses

func NewEnvProvider() envProvider

NewEnvProvider creates provider which sets values from ENV variables (gets variable name from `env` tag)

func NewFileProvider Uses

func NewFileProvider(fileName string) (fp fileProvider)

NewFileProvider creates new provider which read values from files (json, yaml)

func NewFlagProvider Uses

func NewFlagProvider(ptrToCfg interface{}) flagProvider

NewFlagProvider creates a new provider to fetch data from flags like: --flag_name some_value

func SetField Uses

func SetField(field reflect.StructField, v reflect.Value, valStr string)

SetField sets field with `valStr` value (converts to the proper type beforehand)

type Logger Uses

type Logger func(format string, v ...interface{})

type Provider Uses

type Provider interface {
    Provide(field reflect.StructField, v reflect.Value, pathToField ...string) bool

Provider defines interface for existing and future custom providers

Package configuration imports 12 packages (graph). Updated 2020-04-29. Refresh now. Tools for package owners.