lib/ur: Track new folder feature usage (#6803)

This commit is contained in:
Audrius Butkevicius
2020-06-28 20:35:22 +02:00
committed by GitHub
parent d7fc7008af
commit 9d4a700829
4 changed files with 180 additions and 6 deletions
+32
View File
@@ -137,6 +137,38 @@ func UniqueTrimmedStrings(ss []string) []string {
return us
}
func FillNil(data interface{}) {
s := reflect.ValueOf(data).Elem()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
for f.Kind() == reflect.Ptr && f.IsZero() && f.CanSet() {
newValue := reflect.New(f.Type().Elem())
f.Set(newValue)
f = f.Elem()
}
if f.CanSet() {
if f.IsZero() {
switch f.Kind() {
case reflect.Map:
f.Set(reflect.MakeMap(f.Type()))
case reflect.Slice:
f.Set(reflect.MakeSlice(f.Type(), 0, 0))
case reflect.Chan:
f.Set(reflect.MakeChan(f.Type(), 0))
}
}
if f.Kind() == reflect.Struct && f.CanAddr() {
if addr := f.Addr(); addr.CanInterface() {
FillNil(addr.Interface())
}
}
}
}
}
// FillNilSlices sets default value on slices that are still nil.
func FillNilSlices(data interface{}) error {
s := reflect.ValueOf(data).Elem()