package config import ( "errors" "fmt" "strings" "go.wit.com/log" ) func formatENV() (string, error) { if configPB == nil { return "", errors.New("configPB not initialized") } var out string uniques := make(map[string]*Config) // check to make sure there are no duplicate entries for c := range configPB.IterAll() { key := strings.ToLower(c.Key) if len(strings.Fields(key)) != 1 { log.Info("dropping invalid key = ", c.Key, "value =", c.Value) continue } found := findByLower(key) if found == nil { log.Info("findByKey() got nil for key:", key) } // todo: warn about duplicates? uniques[key] = found } for key, c := range uniques { if c == nil { log.Info("key has nil c", key) continue } line := fmt.Sprintf("%s=%s", c.Key, c.Value) out += line + "\n" } return out, nil } func findByLower(lookingFor string) *Config { for c := range configPB.IterAll() { if strings.ToLower(c.Key) == strings.ToLower(lookingFor) { return c } } return nil }