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
}
val, err := sc.GetString(key)
if err != nil || val == "" {
val, ok := sc.Get(key)
if !ok || val == nil {
return nil
}
// Parse comma-separated values
parts := strings.Split(val, ",")
result := make([]string, 0, len(parts))
for _, part := range parts {
trimmed := strings.TrimSpace(part)
if trimmed != "" {
result = append(result, trimmed)
// Handle YAML list format
if slice, ok := val.([]interface{}); ok {
result := make([]string, 0, len(slice))
for _, item := range slice {
if str, ok := item.(string); ok {
trimmed := strings.TrimSpace(str)
if 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
}