Lesson 33 of 60
GoWorking with Environment Variables
10 minutes
Course progress55%
Configuration via Env
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
Use os.Getenv and os.LookupEnv.
port := os.Getenv("PORT")
if port == "" { port = "8080" }
Parsing numbers safely
pStr, ok := os.LookupEnv(); ok {
p, err := strconv.Atoi(pStr); err == {
maxConn = p
}
}