feat: able to set multiple subnets

This commit is contained in:
JustSong
2024-04-05 17:25:28 +08:00
parent dcf24b98dc
commit 348adc2b02
5 changed files with 34 additions and 7 deletions

View File

@@ -102,7 +102,7 @@ func TokenAuth() func(c *gin.Context) {
return
}
if token.Subnet != nil && *token.Subnet != "" {
if !network.IsIpInSubnet(ctx, c.ClientIP(), *token.Subnet) {
if !network.IsIpInSubnets(ctx, c.ClientIP(), *token.Subnet) {
abortWithMessage(c, http.StatusForbidden, fmt.Sprintf("该令牌只能在指定网段使用:%s当前 ip%s", *token.Subnet, c.ClientIP()))
return
}