Support YAML list format for whitelist_hosts config

This commit is contained in:
2026-01-08 04:08:51 -08:00
parent 3fcf9d9146
commit 9647829ac9

View File

@@ -147,21 +147,40 @@ func getStringSlice(sc *smartconfig.Config, key string) []string {
return nil return nil
} }
val, err := sc.GetString(key) val, ok := sc.Get(key)
if err != nil || val == "" { if !ok || val == nil {
return nil return nil
} }
// Parse comma-separated values // Handle YAML list format
parts := strings.Split(val, ",") if slice, ok := val.([]interface{}); ok {
result := make([]string, 0, len(parts)) result := make([]string, 0, len(slice))
for _, item := range slice {
for _, part := range parts { if str, ok := item.(string); ok {
trimmed := strings.TrimSpace(part) trimmed := strings.TrimSpace(str)
if trimmed != "" { if trimmed != "" {
result = append(result, trimmed) result = append(result, trimmed)
}
}
} }
return result
} }
return result // Fall back to comma-separated string for backwards compatibility
if str, ok := val.(string); ok && str != "" {
parts := strings.Split(str, ",")
result := make([]string, 0, len(parts))
for _, part := range parts {
trimmed := strings.TrimSpace(part)
if trimmed != "" {
result = append(result, trimmed)
}
}
return result
}
return nil
} }