Load config into go struct from shell environment and docker/kubernetes secrets.
go get github.com/hack-fan/config- Load from shell environment variables
- Load from Docker/Kubernetes secrets
- Default values support
- Required check support
- Simple and easy to use, no other features
Default -> ENV -> Secret -> Value exists in struct
Right side will overwrite left side.
package main
import (
"fmt"
"github.com/hack-fan/config"
)
type Settings struct {
AppName string `default:"app"` // env APP_NAME will overwrite default value
DB struct {
Name string
User string `required:"true"`
Password string `secret:"mysql_db_password"` // default secret name is 'db_password',change it use tag
Port int `default:"3306" env:"MYSQL_DB_PORT"` // default env name is 'DB_PORT',change it use tag
}
}
func main() {
var settings = new(Settings)
config.MustLoad(settings)
fmt.Printf("%+v",settings)
}ENVwill use ALL_CAP_SNAKE_CASESecretwill use snake_case
defaultset default valueenvcustom shell env variable namessecretcustom secret file namerequiredset attr as required