From ff7faa8d6b1d845776e27f9c137923abd59684f2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 21 Oct 2025 04:48:54 -0500 Subject: trying to get this to work again --- config.FormatENV.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 config.FormatENV.go (limited to 'config.FormatENV.go') diff --git a/config.FormatENV.go b/config.FormatENV.go new file mode 100644 index 0000000..bd3a156 --- /dev/null +++ b/config.FormatENV.go @@ -0,0 +1,51 @@ +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 +} -- cgit v1.2.3