Files
tyapi-server/internal/domains/api/services/processors/dwbg/dwbg6a2c_validate.go
2026-07-08 21:28:08 +08:00

46 lines
932 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}