package env import ( "errors" "fmt" "strings" ) func formatENV() (string, error) { if envPB == nil { return "", errors.New("envPB not initialized") } var out string uniques := make(map[string]*Key) // check to make sure there are no duplicate entries // todo: remove this duplicate entry check once duplicates aren't a problem anymore for c := range envPB.IterAll() { key := strings.ToLower(c.Var) if len(strings.Fields(key)) != 1 { // fmt.Println("dropping invalid key = ", c.Var, "value =", c.Value) continue } found := findByLower(key) if found == nil { // fmt.Println("findByKey() got nil for key:", key) } // todo: warn about duplicates? uniques[key] = found } for key, c := range uniques { _ = key if c == nil { // fmt.Println("key has nil c", key) continue } if c.Global != "" { // don't write out anything defined globally continue } line := fmt.Sprintf("%s=%s", c.Var, c.Value) out += line + "\n" } return out, nil } func findByLower(lookingFor string) *Key { for c := range envPB.IterAll() { if strings.ToLower(c.Var) == strings.ToLower(lookingFor) { return c } } return nil }