Skip to content

Instantly share code, notes, and snippets.

@littlebenlittle
Last active November 10, 2019 15:12
Show Gist options
  • Save littlebenlittle/c5766f3b43c1ebcad3c1acdb4311dc3d to your computer and use it in GitHub Desktop.
Save littlebenlittle/c5766f3b43c1ebcad3c1acdb4311dc3d to your computer and use it in GitHub Desktop.
env parsing in various languages
def parse_env():
vars = [
"CERTFILE",
"SERVER",
]
env = SimpleNamespace()
for v in vars:
setattr(env, v, os.environ[v])
return env
func parseEnv() (map[string]string) {
pass := true
m := make(map[string]string)
for _, k := range []string{
"GRPC_PORT",
"GOOGLE_CLIENT_ID",
"GOOGLE_CLIENT_SECRET",
"CERTFILE",
"KEYFILE",
} {
v := os.Getenv(k)
if v == "" {
pass = false
log.Printf("%s not set", k)
} else {
m[k] = v
}
}
if !pass {
log.Fatal("cannot start due to the above errors")
}
return m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment