Documentation
¶
Overview ¶
Package config provides flexible access to config variables by priority: flags - HI, environment variables - MID, default values defined with a struct field tags - LOW
Index ¶
- Variables
- func Init(c interface{}, prefix string) error
- type FlagSet
- func (f *FlagSet) ArrayDurationVar(p *[]time.Duration, name string, value []time.Duration, usage string)
- func (f *FlagSet) ArrayFloat64Var(p *[]float64, name string, value []float64, usage string)
- func (f *FlagSet) ArrayInt64Var(p *[]int64, name string, value []int64, usage string)
- func (f *FlagSet) ArrayIntVar(p *[]int, name string, value []int, usage string)
- func (f *FlagSet) ArrayStringVar(p *[]string, name string, value []string, usage string)
- func (f *FlagSet) ArrayUint64Var(p *[]uint64, name string, value []uint64, usage string)
- func (f *FlagSet) ArrayUintVar(p *[]uint, name string, value []uint, usage string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var EnvPrefix string
EnvPrefix is a prefix in the beginning of environment variable name (used to easily differentiate variables of your application).
Functions ¶
func Init ¶
Init config values.
Example ¶
package main
import (
"fmt"
"github.com/Alma-media/go-config"
)
// TestConfig struct
type TestConfig struct {
String string `default:"strvalue"`
Int int `default:"42"`
Bool bool `default:"false"`
ArrInt64 []int64 `default:"-1,2,-3,4,-5"`
Nested Nested
}
// Nested config struct
type Nested struct {
String string `default:"nestedstrvalue"`
}
func main() {
var conf TestConfig
fmt.Println(config.Init(&conf, "myapp"), conf)
}
Output: <nil> {strvalue 42 false [-1 2 -3 4 -5] {nestedstrvalue}}
Types ¶
type FlagSet ¶
FlagSet represents extended flag.FlagSet.
func NewFlagSet ¶
func NewFlagSet(name string, errorHandling flag.ErrorHandling) *FlagSet
NewFlagSet returns a new, empty flag set with the specified name and error handling property.
func (*FlagSet) ArrayDurationVar ¶
func (f *FlagSet) ArrayDurationVar(p *[]time.Duration, name string, value []time.Duration, usage string)
ArrayDurationVar defines an []time.Duration flag with specified name, default value, and usage string. The argument p points to an []time.Duration variable in which to store the value of the flag.
func (*FlagSet) ArrayFloat64Var ¶
ArrayFloat64Var defines an []float64 flag with specified name, default value, and usage string. The argument p points to an []float64 variable in which to store the value of the flag.
func (*FlagSet) ArrayInt64Var ¶
ArrayInt64Var defines an []int64 flag with specified name, default value, and usage string. The argument p points to an []int64 variable in which to store the value of the flag.
func (*FlagSet) ArrayIntVar ¶
ArrayIntVar defines an []int flag with specified name, default value, and usage string. The argument p points to an []int variable in which to store the value of the flag.
func (*FlagSet) ArrayStringVar ¶
ArrayStringVar defines an []string flag with specified name, default value, and usage string. The argument p points to an []string variable in which to store the value of the flag.
func (*FlagSet) ArrayUint64Var ¶
ArrayUint64Var defines an []uint64 flag with specified name, default value, and usage string. The argument p points to an []uint64 variable in which to store the value of the flag.