Files
tyapi-server/internal/domains/api/services/processors/dwbg/dwbg6a2c_validate.go

46 lines
932 B
Go
Raw Normal View History

2026-07-08 21:28:08 +08:00
package dwbg
// stripNullValues 递归移除 map/slice 中的 nil避免 JSON 输出 null。
func stripNullValues(v interface{}) interface{} {
switch val := v.(type) {
case map[string]interface{}:
out := make(map[string]interface{}, len(val))
for k, item := range val {
if item == nil {
continue
}
out[k] = stripNullValues(item)
}
return out
case []interface{}:
out := make([]interface{}, 0, len(val))
for _, item := range val {
if item == nil {
continue
}
out = append(out, stripNullValues(item))
}
return out
default:
return v
}
}
func reportContainsNull(v interface{}) bool {
switch val := v.(type) {
case map[string]interface{}:
for _, item := range val {
if item == nil || reportContainsNull(item) {
return true
}
}
case []interface{}:
for _, item := range val {
if item == nil || reportContainsNull(item) {
return true
}
}
}
return false
}