Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
692b5ff5
authored
Dec 15, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(auth): refactor IP restriction handling to use clearer variable naming
parent
947a763a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
middleware/auth.go
+3
-3
No files found.
middleware/auth.go
View file @
692b5ff5
...
@@ -242,8 +242,8 @@ func TokenAuth() func(c *gin.Context) {
...
@@ -242,8 +242,8 @@ func TokenAuth() func(c *gin.Context) {
return
return
}
}
allowIps
Map
:=
token
.
GetIpLimits
()
allowIps
:=
token
.
GetIpLimits
()
if
len
(
allowIps
Map
)
>
0
{
if
len
(
allowIps
)
>
0
{
clientIp
:=
c
.
ClientIP
()
clientIp
:=
c
.
ClientIP
()
logger
.
LogDebug
(
c
,
"Token has IP restrictions, checking client IP %s"
,
clientIp
)
logger
.
LogDebug
(
c
,
"Token has IP restrictions, checking client IP %s"
,
clientIp
)
ip
:=
net
.
ParseIP
(
clientIp
)
ip
:=
net
.
ParseIP
(
clientIp
)
...
@@ -251,7 +251,7 @@ func TokenAuth() func(c *gin.Context) {
...
@@ -251,7 +251,7 @@ func TokenAuth() func(c *gin.Context) {
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
"无法解析客户端 IP 地址"
)
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
"无法解析客户端 IP 地址"
)
return
return
}
}
if
common
.
IsIpInCIDRList
(
ip
,
allowIps
Map
)
==
false
{
if
common
.
IsIpInCIDRList
(
ip
,
allowIps
)
==
false
{
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
"您的 IP 不在令牌允许访问的列表中"
)
abortWithOpenAiMessage
(
c
,
http
.
StatusForbidden
,
"您的 IP 不在令牌允许访问的列表中"
)
return
return
}
}
...
...
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