mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 04:40:52 +08:00
refactor: reduce code duplication in extractExcludedModelsFromMetadata
This commit is contained in:
@@ -273,26 +273,25 @@ func extractExcludedModelsFromMetadata(metadata map[string]any) []string {
|
|||||||
if !ok || raw == nil {
|
if !ok || raw == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
var stringSlice []string
|
||||||
switch v := raw.(type) {
|
switch v := raw.(type) {
|
||||||
case []string:
|
case []string:
|
||||||
result := make([]string, 0, len(v))
|
stringSlice = v
|
||||||
for _, s := range v {
|
|
||||||
if trimmed := strings.TrimSpace(s); trimmed != "" {
|
|
||||||
result = append(result, trimmed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
result := make([]string, 0, len(v))
|
stringSlice = make([]string, 0, len(v))
|
||||||
for _, item := range v {
|
for _, item := range v {
|
||||||
if s, ok := item.(string); ok {
|
if s, ok := item.(string); ok {
|
||||||
if trimmed := strings.TrimSpace(s); trimmed != "" {
|
stringSlice = append(stringSlice, s)
|
||||||
result = append(result, trimmed)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
result := make([]string, 0, len(stringSlice))
|
||||||
|
for _, s := range stringSlice {
|
||||||
|
if trimmed := strings.TrimSpace(s); trimmed != "" {
|
||||||
|
result = append(result, trimmed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user