Env var is not unmarshalled #1203
Answered
by
vasily-kirichenko
vasily-kirichenko
asked this question in
Q&A
-
I guess I'm missing something. Why package main
import (
"fmt"
"github.com/spf13/viper"
"log"
"os"
)
type Config struct {
EXE_PATH string
}
func main() {
if err := os.Setenv("EXE_PATH", "exe path from env"); err != nil {
log.Fatal(err)
}
viper.AutomaticEnv()
var cfg Config
if err := viper.Unmarshal(&cfg); err != nil {
log.Fatal(err)
}
fmt.Printf("EXE_PATH: %v\n", viper.Get("EXE_PATH"))
fmt.Printf("%#v\n", cfg)
}
|
Beta Was this translation helpful? Give feedback.
Answered by
vasily-kirichenko
Sep 3, 2021
Replies: 1 comment
-
Solved, it can be closed. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vasily-kirichenko
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solved, it can be closed.