Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
5dd8b880
Commit
5dd8b880
authored
Jan 04, 2026
by
yangjianbo
Browse files
fix(后端): 修复 lint 失败并清理无用代码
修正测试中的 APIKey 名称引用 移除不可达返回与未使用函数 统一 gofmt 格式并处理 Close 错误
parent
7dddd065
Changes
8
Show whitespace changes
Inline
Side-by-side
backend/internal/config/config.go
View file @
5dd8b880
backend/internal/handler/gateway_handler.go
View file @
5dd8b880
...
...
@@ -13,8 +13,8 @@ import (
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
pkgerrors
"github.com/Wei-Shaw/sub2api/internal/pkg/errors"
"github.com/Wei-Shaw/sub2api/internal/pkg/claude"
pkgerrors
"github.com/Wei-Shaw/sub2api/internal/pkg/errors"
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
middleware2
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
...
...
backend/internal/repository/claude_oauth_service.go
View file @
5dd8b880
...
...
@@ -246,13 +246,3 @@ func createReqClient(proxyURL string) *req.Client {
return
client
}
func
prefix
(
s
string
,
n
int
)
string
{
if
n
<=
0
{
return
""
}
if
len
(
s
)
<=
n
{
return
s
}
return
s
[
:
n
]
}
backend/internal/server/middleware/api_key_auth_google_test.go
View file @
5dd8b880
...
...
@@ -113,12 +113,12 @@ func TestApiKeyAuthWithSubscriptionGoogle_QueryApiKeyRejected(t *testing.T) {
gin
.
SetMode
(
gin
.
TestMode
)
r
:=
gin
.
New
()
apiKeyService
:=
newTestA
pi
KeyService
(
fakeA
pi
KeyRepo
{
getByKey
:
func
(
ctx
context
.
Context
,
key
string
)
(
*
service
.
A
pi
Key
,
error
)
{
apiKeyService
:=
newTestA
PI
KeyService
(
fakeA
PI
KeyRepo
{
getByKey
:
func
(
ctx
context
.
Context
,
key
string
)
(
*
service
.
A
PI
Key
,
error
)
{
return
nil
,
errors
.
New
(
"should not be called"
)
},
})
r
.
Use
(
A
pi
KeyAuthWithSubscriptionGoogle
(
apiKeyService
,
nil
,
&
config
.
Config
{}))
r
.
Use
(
A
PI
KeyAuthWithSubscriptionGoogle
(
apiKeyService
,
nil
,
&
config
.
Config
{}))
r
.
GET
(
"/v1beta/test"
,
func
(
c
*
gin
.
Context
)
{
c
.
JSON
(
200
,
gin
.
H
{
"ok"
:
true
})
})
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/v1beta/test?api_key=legacy"
,
nil
)
...
...
@@ -137,9 +137,9 @@ func TestApiKeyAuthWithSubscriptionGoogle_QueryKeyAllowedOnV1Beta(t *testing.T)
gin
.
SetMode
(
gin
.
TestMode
)
r
:=
gin
.
New
()
apiKeyService
:=
newTestA
pi
KeyService
(
fakeA
pi
KeyRepo
{
getByKey
:
func
(
ctx
context
.
Context
,
key
string
)
(
*
service
.
A
pi
Key
,
error
)
{
return
&
service
.
A
pi
Key
{
apiKeyService
:=
newTestA
PI
KeyService
(
fakeA
PI
KeyRepo
{
getByKey
:
func
(
ctx
context
.
Context
,
key
string
)
(
*
service
.
A
PI
Key
,
error
)
{
return
&
service
.
A
PI
Key
{
ID
:
1
,
Key
:
key
,
Status
:
service
.
StatusActive
,
...
...
@@ -151,7 +151,7 @@ func TestApiKeyAuthWithSubscriptionGoogle_QueryKeyAllowedOnV1Beta(t *testing.T)
},
})
cfg
:=
&
config
.
Config
{
RunMode
:
config
.
RunModeSimple
}
r
.
Use
(
A
pi
KeyAuthWithSubscriptionGoogle
(
apiKeyService
,
nil
,
cfg
))
r
.
Use
(
A
PI
KeyAuthWithSubscriptionGoogle
(
apiKeyService
,
nil
,
cfg
))
r
.
GET
(
"/v1beta/test"
,
func
(
c
*
gin
.
Context
)
{
c
.
JSON
(
200
,
gin
.
H
{
"ok"
:
true
})
})
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/v1beta/test?key=valid"
,
nil
)
...
...
backend/internal/service/billing_cache_service.go
View file @
5dd8b880
...
...
@@ -659,28 +659,3 @@ func circuitStateString(state billingCircuitBreakerState) string {
return
"unknown"
}
}
// checkSubscriptionLimitsFallback 降级检查订阅限额
func
(
s
*
BillingCacheService
)
checkSubscriptionLimitsFallback
(
subscription
*
UserSubscription
,
group
*
Group
)
error
{
if
subscription
==
nil
{
return
ErrSubscriptionInvalid
}
if
!
subscription
.
IsActive
()
{
return
ErrSubscriptionInvalid
}
if
!
subscription
.
CheckDailyLimit
(
group
,
0
)
{
return
ErrDailyLimitExceeded
}
if
!
subscription
.
CheckWeeklyLimit
(
group
,
0
)
{
return
ErrWeeklyLimitExceeded
}
if
!
subscription
.
CheckMonthlyLimit
(
group
,
0
)
{
return
ErrMonthlyLimitExceeded
}
return
nil
}
backend/internal/service/gateway_service.go
View file @
5dd8b880
...
...
@@ -1731,7 +1731,6 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
}
}
return
&
streamingResult
{
usage
:
usage
,
firstTokenMs
:
firstTokenMs
},
nil
}
// replaceModelInSSELine 替换SSE数据行中的model字段
...
...
backend/internal/service/openai_gateway_service.go
View file @
5dd8b880
...
...
@@ -934,7 +934,6 @@ func (s *OpenAIGatewayService) handleStreamingResponse(ctx context.Context, resp
}
}
return
&
openaiStreamingResult
{
usage
:
usage
,
firstTokenMs
:
firstTokenMs
},
nil
}
func
(
s
*
OpenAIGatewayService
)
replaceModelInSSELine
(
line
,
fromModel
,
toModel
string
)
string
{
...
...
backend/internal/service/openai_gateway_service_test.go
View file @
5dd8b880
...
...
@@ -72,7 +72,7 @@ func TestOpenAIStreamingTooLong(t *testing.T) {
}
go
func
()
{
defer
pw
.
Close
()
defer
func
()
{
_
=
pw
.
Close
()
}()
// 写入超过 MaxLineSize 的单行数据,触发 ErrTooLong
payload
:=
"data: "
+
strings
.
Repeat
(
"a"
,
128
*
1024
)
+
"
\n
"
_
,
_
=
pw
.
Write
([]
byte
(
payload
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment