package models // Sanitizer interface for models that can sanitize themselves type Sanitizer interface { Sanitized() map[string]interface{} } // SanitizedJSON sanitizes a single model or a slice of models func SanitizedJSON(v any) any { switch val := v.(type) { // Single objects case User: return val.Sanitized() case *User: if val == nil { return nil } return val.Sanitized() case Cluster: return val.Sanitized() case *Cluster: if val == nil { return nil } return val.Sanitized() case Host: return val.Sanitized() case *Host: if val == nil { return nil } return val.Sanitized() case StorageConfig: return val.Sanitized() case *StorageConfig: if val == nil { return nil } return val.Sanitized() // Slices case []User: result := make([]map[string]interface{}, len(val)) for i, item := range val { result[i] = item.Sanitized() } return result case []Cluster: result := make([]map[string]interface{}, len(val)) for i, item := range val { result[i] = item.Sanitized() } return result case []Host: result := make([]map[string]interface{}, len(val)) for i, item := range val { result[i] = item.Sanitized() } return result case []StorageConfig: result := make([]map[string]interface{}, len(val)) for i, item := range val { result[i] = item.Sanitized() } return result default: return v } }