Last active
November 10, 2019 15:12
-
-
Save littlebenlittle/c5766f3b43c1ebcad3c1acdb4311dc3d to your computer and use it in GitHub Desktop.
env parsing in various languages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_env(): | |
vars = [ | |
"CERTFILE", | |
"SERVER", | |
] | |
env = SimpleNamespace() | |
for v in vars: | |
setattr(env, v, os.environ[v]) | |
return env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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