fix: 修复golangci-lint检查问题
- 移除OpenAIGatewayHandler中未使用的userService字段 - 将账号类型判断的if-else链改为switch语句
This commit is contained in:
@@ -111,7 +111,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|||||||
concurrencyService := service.NewConcurrencyService(concurrencyCache)
|
concurrencyService := service.NewConcurrencyService(concurrencyCache)
|
||||||
gatewayHandler := handler.NewGatewayHandler(gatewayService, userService, concurrencyService, billingCacheService)
|
gatewayHandler := handler.NewGatewayHandler(gatewayService, userService, concurrencyService, billingCacheService)
|
||||||
openAIGatewayService := service.NewOpenAIGatewayService(accountRepository, usageLogRepository, userRepository, userSubscriptionRepository, gatewayCache, configConfig, billingService, rateLimitService, billingCacheService, httpUpstream)
|
openAIGatewayService := service.NewOpenAIGatewayService(accountRepository, usageLogRepository, userRepository, userSubscriptionRepository, gatewayCache, configConfig, billingService, rateLimitService, billingCacheService, httpUpstream)
|
||||||
openAIGatewayHandler := handler.NewOpenAIGatewayHandler(openAIGatewayService, userService, concurrencyService, billingCacheService)
|
openAIGatewayHandler := handler.NewOpenAIGatewayHandler(openAIGatewayService, concurrencyService, billingCacheService)
|
||||||
handlerSettingHandler := handler.ProvideSettingHandler(settingService, buildInfo)
|
handlerSettingHandler := handler.ProvideSettingHandler(settingService, buildInfo)
|
||||||
handlers := handler.ProvideHandlers(authHandler, userHandler, apiKeyHandler, usageHandler, redeemHandler, subscriptionHandler, adminHandlers, gatewayHandler, openAIGatewayHandler, handlerSettingHandler)
|
handlers := handler.ProvideHandlers(authHandler, userHandler, apiKeyHandler, usageHandler, redeemHandler, subscriptionHandler, adminHandlers, gatewayHandler, openAIGatewayHandler, handlerSettingHandler)
|
||||||
groupService := service.NewGroupService(groupRepository)
|
groupService := service.NewGroupService(groupRepository)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import (
|
|||||||
// OpenAIGatewayHandler handles OpenAI API gateway requests
|
// OpenAIGatewayHandler handles OpenAI API gateway requests
|
||||||
type OpenAIGatewayHandler struct {
|
type OpenAIGatewayHandler struct {
|
||||||
gatewayService *service.OpenAIGatewayService
|
gatewayService *service.OpenAIGatewayService
|
||||||
userService *service.UserService
|
|
||||||
billingCacheService *service.BillingCacheService
|
billingCacheService *service.BillingCacheService
|
||||||
concurrencyHelper *ConcurrencyHelper
|
concurrencyHelper *ConcurrencyHelper
|
||||||
}
|
}
|
||||||
@@ -27,13 +26,11 @@ type OpenAIGatewayHandler struct {
|
|||||||
// NewOpenAIGatewayHandler creates a new OpenAIGatewayHandler
|
// NewOpenAIGatewayHandler creates a new OpenAIGatewayHandler
|
||||||
func NewOpenAIGatewayHandler(
|
func NewOpenAIGatewayHandler(
|
||||||
gatewayService *service.OpenAIGatewayService,
|
gatewayService *service.OpenAIGatewayService,
|
||||||
userService *service.UserService,
|
|
||||||
concurrencyService *service.ConcurrencyService,
|
concurrencyService *service.ConcurrencyService,
|
||||||
billingCacheService *service.BillingCacheService,
|
billingCacheService *service.BillingCacheService,
|
||||||
) *OpenAIGatewayHandler {
|
) *OpenAIGatewayHandler {
|
||||||
return &OpenAIGatewayHandler{
|
return &OpenAIGatewayHandler{
|
||||||
gatewayService: gatewayService,
|
gatewayService: gatewayService,
|
||||||
userService: userService,
|
|
||||||
billingCacheService: billingCacheService,
|
billingCacheService: billingCacheService,
|
||||||
concurrencyHelper: NewConcurrencyHelper(concurrencyService, SSEPingFormatNone),
|
concurrencyHelper: NewConcurrencyHelper(concurrencyService, SSEPingFormatNone),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,20 +179,22 @@ func (s *OpenAIGatewayService) SelectAccountForModel(ctx context.Context, groupI
|
|||||||
|
|
||||||
// GetAccessToken gets the access token for an OpenAI account
|
// GetAccessToken gets the access token for an OpenAI account
|
||||||
func (s *OpenAIGatewayService) GetAccessToken(ctx context.Context, account *model.Account) (string, string, error) {
|
func (s *OpenAIGatewayService) GetAccessToken(ctx context.Context, account *model.Account) (string, string, error) {
|
||||||
if account.Type == model.AccountTypeOAuth {
|
switch account.Type {
|
||||||
|
case model.AccountTypeOAuth:
|
||||||
accessToken := account.GetOpenAIAccessToken()
|
accessToken := account.GetOpenAIAccessToken()
|
||||||
if accessToken == "" {
|
if accessToken == "" {
|
||||||
return "", "", errors.New("access_token not found in credentials")
|
return "", "", errors.New("access_token not found in credentials")
|
||||||
}
|
}
|
||||||
return accessToken, "oauth", nil
|
return accessToken, "oauth", nil
|
||||||
} else if account.Type == model.AccountTypeApiKey {
|
case model.AccountTypeApiKey:
|
||||||
apiKey := account.GetOpenAIApiKey()
|
apiKey := account.GetOpenAIApiKey()
|
||||||
if apiKey == "" {
|
if apiKey == "" {
|
||||||
return "", "", errors.New("api_key not found in credentials")
|
return "", "", errors.New("api_key not found in credentials")
|
||||||
}
|
}
|
||||||
return apiKey, "apikey", nil
|
return apiKey, "apikey", nil
|
||||||
|
default:
|
||||||
|
return "", "", fmt.Errorf("unsupported account type: %s", account.Type)
|
||||||
}
|
}
|
||||||
return "", "", fmt.Errorf("unsupported account type: %s", account.Type)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forward forwards request to OpenAI API
|
// Forward forwards request to OpenAI API
|
||||||
@@ -295,10 +297,11 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
|
|||||||
func (s *OpenAIGatewayService) buildUpstreamRequest(ctx context.Context, c *gin.Context, account *model.Account, body []byte, token string, isStream bool) (*http.Request, error) {
|
func (s *OpenAIGatewayService) buildUpstreamRequest(ctx context.Context, c *gin.Context, account *model.Account, body []byte, token string, isStream bool) (*http.Request, error) {
|
||||||
// Determine target URL based on account type
|
// Determine target URL based on account type
|
||||||
var targetURL string
|
var targetURL string
|
||||||
if account.Type == model.AccountTypeOAuth {
|
switch account.Type {
|
||||||
|
case model.AccountTypeOAuth:
|
||||||
// OAuth accounts use ChatGPT internal API
|
// OAuth accounts use ChatGPT internal API
|
||||||
targetURL = chatgptCodexURL
|
targetURL = chatgptCodexURL
|
||||||
} else if account.Type == model.AccountTypeApiKey {
|
case model.AccountTypeApiKey:
|
||||||
// API Key accounts use Platform API or custom base URL
|
// API Key accounts use Platform API or custom base URL
|
||||||
baseURL := account.GetOpenAIBaseURL()
|
baseURL := account.GetOpenAIBaseURL()
|
||||||
if baseURL != "" {
|
if baseURL != "" {
|
||||||
@@ -306,7 +309,7 @@ func (s *OpenAIGatewayService) buildUpstreamRequest(ctx context.Context, c *gin.
|
|||||||
} else {
|
} else {
|
||||||
targetURL = openaiPlatformAPIURL
|
targetURL = openaiPlatformAPIURL
|
||||||
}
|
}
|
||||||
} else {
|
default:
|
||||||
targetURL = openaiPlatformAPIURL
|
targetURL = openaiPlatformAPIURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user