load evn config to struct
package main
import (
"fmt"
"github.com/sillyhatxu/env-utils"
"os"
"strings"
"testing"
)
type EnvConfig struct {
TestString string `env:"TEST.STRING"`
TestInt int `env:"TEST.INT"`
TestInt8 int8 `env:"TEST.INT8"`
TestInt32 int32 `env:"TEST.INT32"`
TestInt64 int64 `env:"TEST.INT64"`
TestBoolean bool `env:"TEST.BOOLEAN"`
TestFloat32 float32 `env:"TEST.FLOAT32"`
TestFloat64 float64 `env:"TEST.FLOAT64"`
TestURL string `env:"TEST.URL"`
TestNilString string `env:"TEST.NIL_STRING"`
}
func main() {
var config EnvConfig
fileName := ""
if os.Getenv("APPLICATION_ENV") == "" {
fileName = "local.env"
} else {
fileName = ".env"
}
err := envutils.ParseConfig(&config, envutils.Filenames([]string{fileName}))
if err != nil{
panic(err)
}
fmt.Println(config.TestString)
fmt.Println(config.TestURL)
fmt.Println(config.TestNilString)
fmt.Println(config.TestInt)
fmt.Println(config.TestInt8)
fmt.Println(config.TestInt32)
fmt.Println(config.TestInt64)
fmt.Println(config.TestBoolean)
fmt.Println(config.TestFloat64)
fmt.Println(config.TestFloat64)
}