Utility package to read the configuration.
go get -u github.com/tiny-go/config- Import package
github.com/tiny-go/config - Create a config struct
- Set default values (if needed) for struct fields
- Pass the pointer to a struct to
Init()func - Check error and enjoy
boolint,[]intuint,[]uintint64,[]int64uint64,[]uint64float64,[]float64time.Duration,[]time.Durationstring,[]string
- flags - hi
- env vars - mid
- defaults - low
package main
import (
"fmt"
"github.com/tiny-go/config"
)
type Config struct {
Boolean bool `default:"true"`
Nested struct {
Integer int `default:"42"`
Float64 float64 `default:"3.14"`
String string `default:"text"`
}
}
func main() {
// create an instance
conf := &Config{}
// pass to Init() func and check the error
if err := config.Init(conf, "MYAPP"); err != nil {
fmt.Println(err)
}
// use your config
fmt.Println(conf)
}