goprop
Golang util for bind environment to the struct and validate with validator.
Usage
Use default, read environmet which start with APP_
package main
import (
"fmt"
"os"
"time"
"github.com/tongium/goprop"
)
type Configuration struct {
Name string
Number int
Digit float64
SomeWord string
Duration time.Duration
CustomName string `env:"CUS"` // specific environment name
}
func init() {
os.Setenv("APP_NAME", "Gopher")
os.Setenv("APP_DURATION", "1h")
os.Setenv("APP_SOME_WORD", "Hello World!")
os.Setenv("APP_DIGIT", "1.23")
os.Setenv("APP_NUMBER", "1")
}
func main() {
cfg := Configuration{}
if err := goprop.Load(&cfg); err != nil {
panic(err)
}
fmt.Printf("%+v\n", cfg)
}
result
{Name:Gopher Number:1 Digit:1.23 SomeWord:Hello World! Duration:1h0m0s}
see more example