Fixing env based layer; not using onion builtin mechanism to preserve opencloud conf key/value format
This commit is contained in:
parent
1de4888599
commit
21d08204b5
@ -26,12 +26,12 @@ import (
|
|||||||
func GetConfLoader() *onion.Onion {
|
func GetConfLoader() *onion.Onion {
|
||||||
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
|
logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
|
||||||
AppName := GetAppName()
|
AppName := GetAppName()
|
||||||
EnvPrefix := strings.ToUpper(AppName[0:2] + AppName[3:])
|
EnvPrefix := strings.ToUpper(AppName[0:2]+AppName[3:]) + "_"
|
||||||
defaultConfigFile := "/etc/oc/" + AppName[3:] + ".json"
|
defaultConfigFile := "/etc/oc/" + AppName[3:] + ".json"
|
||||||
localConfigFile := "./" + AppName[3:] + ".json"
|
localConfigFile := "./" + AppName[3:] + ".json"
|
||||||
var configFile string
|
var configFile string
|
||||||
var o *onion.Onion
|
var o *onion.Onion
|
||||||
l3 := onion.NewEnvLayerPrefix("_", EnvPrefix)
|
l3 := GetEnvVarLayer(EnvPrefix)
|
||||||
l2, err := onion.NewFileLayer(localConfigFile, nil)
|
l2, err := onion.NewFileLayer(localConfigFile, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logger.Info().Msg("Local config file found " + localConfigFile + ", overriding default file")
|
logger.Info().Msg("Local config file found " + localConfigFile + ", overriding default file")
|
||||||
@ -54,3 +54,17 @@ func GetConfLoader() *onion.Onion {
|
|||||||
}
|
}
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetEnvVarLayer(prefix string) onion.Layer {
|
||||||
|
envVars := make(map[string]interface{})
|
||||||
|
|
||||||
|
for _, e := range os.Environ() {
|
||||||
|
pair := strings.SplitN(e, "=", 2)
|
||||||
|
key := pair[0]
|
||||||
|
if strings.HasPrefix(key, prefix) {
|
||||||
|
envVars[strings.TrimPrefix(key, prefix)] = pair[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return onion.NewMapLayer(envVars)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user