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
bool
int
,[]int
uint
,[]uint
int64
,[]int64
uint64
,[]uint64
float64
,[]float64
time.Duration
,[]time.Duration
string
,[]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)
}