-
package main
import (
"fmt"
"github.com/caarlos0/env/v6"
"os"
)
type config struct {
test float64 `env:"YYYY" envDefault:"1.531"`
Hostname string `env:"HOSTNAME" envDefault:"unknown"`
}
func main() {
os.Clearenv()
tos := func(v interface{}) string {
return fmt.Sprintf("%v", v)
}
cfg := config{}
float_str := tos(1.54444)
fmt.Println(float_str)
os.Setenv("HOSTNAME", "NONNONO")
os.Setenv("YYYY", float_str)
if err := env.Parse(&cfg); err != nil {
fmt.Println("%+v\n", err)
}
fmt.Printf("%f\n", cfg.test)
fmt.Println(cfg)
} Output:
Can anyone help take a look? |
Beta Was this translation helpful? Give feedback.
Answered by
caarlos0
Jun 2, 2021
Replies: 1 comment
-
env only works on exported fields, and your |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
caarlos0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
env only works on exported fields, and your
test
field isn't.check https://play.golang.org/p/jSswIjPIYKt