Skip to content

Commit

Permalink
Fix type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
koho committed Mar 3, 2024
1 parent 47cf21f commit 5bbcef1
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions pkg/config/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,36 +562,45 @@ func toMap(in any, tag string) (map[string]any, error) {
if key != "" {
key = strings.Split(key, ",")[0]
}
if key == "-" {
continue
}
switch fv.Kind() {
case reflect.Struct, reflect.Interface:
value := fv.Interface()
if value == nil {
continue
}
if o, ok := value.(time.Time); ok && !o.IsZero() && key != "" {
if b, err := o.MarshalText(); err != nil {
switch o := value.(type) {
case time.Time:
if !o.IsZero() && key != "" {
if b, err := o.MarshalText(); err != nil {
return nil, err
} else {
out[key] = string(b)
}
}
case types.BandwidthQuantity:
if o.String() != "" && key != "" {
out[key] = o.String()
}
default:
m, err := toMap(value, tag)
if err != nil {
return nil, err
} else {
out[key] = string(b)
}
}
if o, ok := value.(types.BandwidthQuantity); ok && o.String() != "" && key != "" {
out[key] = o.String()
continue
}
m, err := toMap(value, tag)
if err != nil {
return nil, err
}
if len(m) == 0 {
continue
}
if key == "" {
for k, v := range m {
out[k] = v
if len(m) == 0 {
continue
}
if key == "" {
if ft.Anonymous {
for k, v := range m {
out[k] = v
}
}
} else {
out[key] = m
}
} else {
out[key] = m
}
case reflect.Slice:
if key == "" || fv.Len() == 0 {
Expand Down

0 comments on commit 5bbcef1

Please sign in to comment.