DEV Community

Discussion on: Reading from Go's .Env

Collapse
 
alexsuslov profile image
Alex Suslov

Best way is replace os.Getenv("NAME_TOKEN") with GetPanic("NAME_TOKEN").

// https://github.com/alexsuslov/godotenv/blob/master/load.go
// GetPanic get variable or panic
func GetPanic(key string) string {
    v, _ := syscall.Getenv(key)
    if v == "" {
        panic(key)
    }
    return v
}