fix(backend): 修复 golangci-lint 报告的格式和代码规范问题

- gofmt: 修复 account_handler.go, models.go, gemini_messages_compat_service.go 的格式
- staticcheck ST1005: 将 error strings 改为小写开头
This commit is contained in:
ianshaw
2025-12-25 21:46:02 -08:00
parent efa470efc7
commit 6682d06c99
3 changed files with 45 additions and 46 deletions

View File

@@ -40,4 +40,3 @@ func FallbackModel(model string) Model {
} }
return Model{Name: "models/" + model, SupportedGenerationMethods: methods} return Model{Name: "models/" + model, SupportedGenerationMethods: methods}
} }

View File

@@ -19,8 +19,8 @@ import (
"time" "time"
"github.com/Wei-Shaw/sub2api/internal/model" "github.com/Wei-Shaw/sub2api/internal/model"
"github.com/Wei-Shaw/sub2api/internal/pkg/googleapi"
"github.com/Wei-Shaw/sub2api/internal/pkg/geminicli" "github.com/Wei-Shaw/sub2api/internal/pkg/geminicli"
"github.com/Wei-Shaw/sub2api/internal/pkg/googleapi"
"github.com/Wei-Shaw/sub2api/internal/service/ports" "github.com/Wei-Shaw/sub2api/internal/service/ports"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -265,7 +265,7 @@ func (s *GeminiMessagesCompatService) Forward(ctx context.Context, c *gin.Contex
buildReq = func(ctx context.Context) (*http.Request, string, error) { buildReq = func(ctx context.Context) (*http.Request, string, error) {
apiKey := account.GetCredential("api_key") apiKey := account.GetCredential("api_key")
if strings.TrimSpace(apiKey) == "" { if strings.TrimSpace(apiKey) == "" {
return nil, "", errors.New("Gemini api_key not configured") return nil, "", errors.New("gemini api_key not configured")
} }
baseURL := strings.TrimRight(account.GetCredential("base_url"), "/") baseURL := strings.TrimRight(account.GetCredential("base_url"), "/")
@@ -295,7 +295,7 @@ func (s *GeminiMessagesCompatService) Forward(ctx context.Context, c *gin.Contex
case model.AccountTypeOAuth: case model.AccountTypeOAuth:
buildReq = func(ctx context.Context) (*http.Request, string, error) { buildReq = func(ctx context.Context) (*http.Request, string, error) {
if s.tokenProvider == nil { if s.tokenProvider == nil {
return nil, "", errors.New("Gemini token provider not configured") return nil, "", errors.New("gemini token provider not configured")
} }
accessToken, err := s.tokenProvider.GetAccessToken(ctx, account) accessToken, err := s.tokenProvider.GetAccessToken(ctx, account)
if err != nil { if err != nil {
@@ -509,7 +509,7 @@ func (s *GeminiMessagesCompatService) ForwardNative(ctx context.Context, c *gin.
buildReq = func(ctx context.Context) (*http.Request, string, error) { buildReq = func(ctx context.Context) (*http.Request, string, error) {
apiKey := account.GetCredential("api_key") apiKey := account.GetCredential("api_key")
if strings.TrimSpace(apiKey) == "" { if strings.TrimSpace(apiKey) == "" {
return nil, "", errors.New("Gemini api_key not configured") return nil, "", errors.New("gemini api_key not configured")
} }
baseURL := strings.TrimRight(account.GetCredential("base_url"), "/") baseURL := strings.TrimRight(account.GetCredential("base_url"), "/")
@@ -535,7 +535,7 @@ func (s *GeminiMessagesCompatService) ForwardNative(ctx context.Context, c *gin.
case model.AccountTypeOAuth: case model.AccountTypeOAuth:
buildReq = func(ctx context.Context) (*http.Request, string, error) { buildReq = func(ctx context.Context) (*http.Request, string, error) {
if s.tokenProvider == nil { if s.tokenProvider == nil {
return nil, "", errors.New("Gemini token provider not configured") return nil, "", errors.New("gemini token provider not configured")
} }
accessToken, err := s.tokenProvider.GetAccessToken(ctx, account) accessToken, err := s.tokenProvider.GetAccessToken(ctx, account)
if err != nil { if err != nil {
@@ -1582,12 +1582,12 @@ func (s *GeminiMessagesCompatService) ForwardAIStudioGET(ctx context.Context, ac
case model.AccountTypeApiKey: case model.AccountTypeApiKey:
apiKey := strings.TrimSpace(account.GetCredential("api_key")) apiKey := strings.TrimSpace(account.GetCredential("api_key"))
if apiKey == "" { if apiKey == "" {
return nil, errors.New("Gemini api_key not configured") return nil, errors.New("gemini api_key not configured")
} }
req.Header.Set("x-goog-api-key", apiKey) req.Header.Set("x-goog-api-key", apiKey)
case model.AccountTypeOAuth: case model.AccountTypeOAuth:
if s.tokenProvider == nil { if s.tokenProvider == nil {
return nil, errors.New("Gemini token provider not configured") return nil, errors.New("gemini token provider not configured")
} }
accessToken, err := s.tokenProvider.GetAccessToken(ctx, account) accessToken, err := s.tokenProvider.GetAccessToken(ctx, account)
if err != nil { if err != nil {