[MM-16719] Setting the MM_SQLSETTINGS_DATASOURCEREPLICAS environment variable breaks the server startup (#11504)

* [MM-16719] fixing reflection: now recursing on value, not interface

adding defaults to cfgWithoutEnvOverrides
adding tests

* don't modify the minimalConfig
Этот коммит содержится в:
Christopher Poile
2019-07-05 18:10:48 -04:00
коммит произвёл GitHub
родитель 620d941b6e
Коммит 8d100af052
4 изменённых файлов: 493 добавлений и 33 удалений

Просмотреть файл

@@ -46,16 +46,26 @@ func getPathsRec(src interface{}, curPath []string) [][]string {
// and returns the reflect.Value of the leaf at the end `path`
func getVal(src interface{}, path []string) reflect.Value {
var val reflect.Value
if reflect.ValueOf(src).Kind() == reflect.Ptr {
val = reflect.ValueOf(src).Elem().FieldByName(path[0])
// If we recursed on a Value, we already have it. If we're calling on an interface{}, get the Value.
switch v := src.(type) {
case reflect.Value:
val = v
default:
val = reflect.ValueOf(src)
}
// Move into the struct
if val.Kind() == reflect.Ptr {
val = val.Elem().FieldByName(path[0])
} else {
val = reflect.ValueOf(src).FieldByName(path[0])
val = val.FieldByName(path[0])
}
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
if val.Kind() == reflect.Struct {
return getVal(val.Interface(), path[1:])
return getVal(val, path[1:])
}
return val
}