diff options
Diffstat (limited to 'formatENV.go')
| -rw-r--r-- | formatENV.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/formatENV.go b/formatENV.go new file mode 100644 index 0000000..0d1efc3 --- /dev/null +++ b/formatENV.go @@ -0,0 +1,51 @@ +package ENV + +import ( + "errors" + "fmt" + "strings" + + "go.wit.com/log" +) + +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 + + for c := range envPB.IterAll() { + key := strings.ToLower(c.Var) + if len(strings.Fields(key)) != 1 { + log.Info("dropping invalid key = ", c.Var, "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.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 +} |
