diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2018-05-03 09:55:03 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-03 09:55:03 -0400 |
commit | 3b138c8b16668f17bfcd367d05b5f7846d185caf (patch) | |
tree | 3fd891b1046544519c3d2491b0c28b93b3d8ad2e /utils/config.go | |
parent | ffb834ec3ce048db341e2438c0116475297a6f74 (diff) | |
download | chat-3b138c8b16668f17bfcd367d05b5f7846d185caf.tar.gz chat-3b138c8b16668f17bfcd367d05b5f7846d185caf.tar.bz2 chat-3b138c8b16668f17bfcd367d05b5f7846d185caf.zip |
MM-10189 Fixed inconsistency when using environment variables for MessageExportSettings (#8705)
Diffstat (limited to 'utils/config.go')
-rw-r--r-- | utils/config.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/utils/config.go b/utils/config.go index 34cd0ed9f..3827cf4ee 100644 --- a/utils/config.go +++ b/utils/config.go @@ -217,7 +217,7 @@ func newViper(allowEnvironmentOverrides bool) *viper.Viper { // Set zeroed defaults for all the config settings so that Viper knows what environment variables // it needs to be looking for. The correct defaults will later be applied using Config.SetDefaults. - defaults := flattenStructToMap(structToMap(reflect.TypeOf(model.Config{}))) + defaults := getDefaultsFromStruct(model.Config{}) for key, value := range defaults { v.SetDefault(key, value) @@ -226,6 +226,10 @@ func newViper(allowEnvironmentOverrides bool) *viper.Viper { return v } +func getDefaultsFromStruct(s interface{}) map[string]interface{} { + return flattenStructToMap(structToMap(reflect.TypeOf(s))) +} + // Converts a struct type into a nested map with keys matching the struct's fields and values // matching the zeroed value of the corresponding field. func structToMap(t reflect.Type) (out map[string]interface{}) { @@ -251,7 +255,14 @@ func structToMap(t reflect.Type) (out map[string]interface{}) { case reflect.Struct: value = structToMap(field.Type) case reflect.Ptr: - value = nil + indirectType := field.Type.Elem() + + if indirectType.Kind() == reflect.Struct { + // Follow pointers to structs since we need to define defaults for their fields + value = structToMap(indirectType) + } else { + value = nil + } default: value = reflect.Zero(field.Type).Interface() } |