mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
Refactor codebase
This commit is contained in:
@@ -11,9 +11,17 @@ import (
|
||||
// It analyzes the model name string to identify which service provider it belongs to.
|
||||
//
|
||||
// Supported providers:
|
||||
// - "gemini" for Google's Gemini models
|
||||
// - "gpt" for OpenAI's GPT models
|
||||
// - "unknow" for unrecognized model names
|
||||
// - "gemini" for Google's Gemini models
|
||||
// - "gpt" for OpenAI's GPT models
|
||||
// - "claude" for Anthropic's Claude models
|
||||
// - "qwen" for Alibaba's Qwen models
|
||||
// - "unknow" for unrecognized model names
|
||||
//
|
||||
// Parameters:
|
||||
// - modelName: The name of the model to identify the provider for.
|
||||
//
|
||||
// Returns:
|
||||
// - string: The name of the provider.
|
||||
func GetProviderName(modelName string) string {
|
||||
if strings.Contains(modelName, "gemini") {
|
||||
return "gemini"
|
||||
@@ -28,3 +36,40 @@ func GetProviderName(modelName string) string {
|
||||
}
|
||||
return "unknow"
|
||||
}
|
||||
|
||||
// InArray checks if a string exists in a slice of strings.
|
||||
// It iterates through the slice and returns true if the target string is found,
|
||||
// otherwise it returns false.
|
||||
//
|
||||
// Parameters:
|
||||
// - hystack: The slice of strings to search in
|
||||
// - needle: The string to search for
|
||||
//
|
||||
// Returns:
|
||||
// - bool: True if the string is found, false otherwise
|
||||
func InArray(hystack []string, needle string) bool {
|
||||
for _, item := range hystack {
|
||||
if needle == item {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HideAPIKey obscures an API key for logging purposes, showing only the first and last few characters.
|
||||
//
|
||||
// Parameters:
|
||||
// - apiKey: The API key to hide.
|
||||
//
|
||||
// Returns:
|
||||
// - string: The obscured API key.
|
||||
func HideAPIKey(apiKey string) string {
|
||||
if len(apiKey) > 8 {
|
||||
return apiKey[:4] + "..." + apiKey[len(apiKey)-4:]
|
||||
} else if len(apiKey) > 4 {
|
||||
return apiKey[:2] + "..." + apiKey[len(apiKey)-2:]
|
||||
} else if len(apiKey) > 2 {
|
||||
return apiKey[:1] + "..." + apiKey[len(apiKey)-1:]
|
||||
}
|
||||
return apiKey
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user