()
| 68 | } |
| 69 | |
| 70 | func (channel *Channel) getKeys() []string { |
| 71 | if channel.Key == "" { |
| 72 | return []string{} |
| 73 | } |
| 74 | trimmed := strings.TrimSpace(channel.Key) |
| 75 | // If the key starts with '[', try to parse it as a JSON array (e.g., for Vertex AI scenarios) |
| 76 | if strings.HasPrefix(trimmed, "[") { |
| 77 | var arr []json.RawMessage |
| 78 | if err := json.Unmarshal([]byte(trimmed), &arr); err == nil { |
| 79 | res := make([]string, len(arr)) |
| 80 | for i, v := range arr { |
| 81 | res[i] = string(v) |
| 82 | } |
| 83 | return res |
| 84 | } |
| 85 | } |
| 86 | // Otherwise, fall back to splitting by newline |
| 87 | keys := strings.Split(strings.Trim(channel.Key, "\n"), "\n") |
| 88 | return keys |
| 89 | } |
| 90 | |
| 91 | func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) { |
| 92 | // If not in multi-key mode, return the original key string directly. |
no outgoing calls
no test coverage detected