if v, ok := os.LookupEnv("IDAASHTTPPORT"); ok {
c.HTTPPort, _ = strconv.Atoi(v)
}
if v, ok := os.LookupEnv("IDAASDBNAME"); ok {
c.DBUserName = v
}
if v, ok := os.LookupEnv("IDAASDBPW"); ok {
c.DBPasswd = v
}
if v, ok := os.LookupEnv("IDAASDBPORT"); ok {
c.DBPort, _ = strconv.Atoi(v)
}
if v, ok := os.LookupEnv("IDAASDBHOST"); ok {
c.DBHost = v
}
'c' is the following struct
type Configuration struct {
HTTPPort int
DBUserName string
DBPasswd string
DBPort int
DBHost string
}
I only want to update the struct field if the environment variable exists. Seems like some little cute map iterator or something like that would work, but I can't figure out a nice solution.