1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/cfg/parsers.go
2019-09-06 20:52:26 -07:00

29 lines
643 B
Go

package cfg
import (
"fmt"
"github.com/olebedev/config"
)
// ParseAsMapOrList takes a configuration key and attempts to parse it first as a map
// and then as a list. Map entries are concatenated as "key/value"
func ParseAsMapOrList(ymlConfig *config.Config, configKey string) []string {
result := []string{}
mapItems, err := ymlConfig.Map(configKey)
if err == nil {
for key, value := range mapItems {
result = append(result, fmt.Sprintf("%s/%s", value, key))
}
return result
}
listItems := ymlConfig.UList(configKey)
for _, listItem := range listItems {
result = append(result, listItem.(string))
}
return result
}