更新提取接口参数,完善流程与测试代码逻辑
This commit is contained in:
@@ -33,16 +33,18 @@ type channelService struct {
|
||||
type ChannelAuthType int
|
||||
|
||||
const (
|
||||
ChannelAuthTypeIp = iota
|
||||
ChannelAuthTypeAll ChannelAuthType = iota
|
||||
ChannelAuthTypeIp
|
||||
ChannelAuthTypePass
|
||||
)
|
||||
|
||||
type ChannelProtocol int32
|
||||
|
||||
const (
|
||||
ProtocolHTTP = ChannelProtocol(1)
|
||||
ProtocolHttps = ChannelProtocol(2)
|
||||
ProtocolSocks5 = ChannelProtocol(3)
|
||||
ProtocolAll ChannelProtocol = iota
|
||||
ProtocolHTTP
|
||||
ProtocolHttps
|
||||
ProtocolSocks5
|
||||
)
|
||||
|
||||
type ResourceInfo struct {
|
||||
@@ -53,10 +55,10 @@ type ResourceInfo struct {
|
||||
Live int32
|
||||
DailyLimit int32
|
||||
DailyUsed int32
|
||||
DailyLast time.Time
|
||||
DailyLast common.LocalDateTime
|
||||
Quota int32
|
||||
Used int32
|
||||
Expire time.Time
|
||||
Expire common.LocalDateTime
|
||||
}
|
||||
|
||||
// region RemoveChannel
|
||||
@@ -313,7 +315,7 @@ func (s *channelService) CreateChannel(
|
||||
Used: resource.Used + int32(count),
|
||||
DailyLast: common.LocalDateTime(now),
|
||||
}
|
||||
last := resource.DailyLast
|
||||
last := time.Time(resource.DailyLast)
|
||||
if now.Year() != last.Year() || now.Month() != last.Month() || now.Day() != last.Day() {
|
||||
toUpdate.DailyUsed = int32(count)
|
||||
} else {
|
||||
@@ -365,7 +367,7 @@ func checkUser(auth *AuthContext, resource *ResourceInfo, count int) error {
|
||||
}
|
||||
|
||||
// 检查每日限额
|
||||
today := time.Now().Format("2006-01-02") == resource.DailyLast.Format("2006-01-02")
|
||||
today := time.Now().Format("2006-01-02") == time.Time(resource.DailyLast).Format("2006-01-02")
|
||||
dailyRemain := int(math.Max(float64(resource.DailyLimit-resource.DailyUsed), 0))
|
||||
if today && dailyRemain < count {
|
||||
return ChannelServiceErr("套餐每日配额不足")
|
||||
@@ -373,7 +375,7 @@ func checkUser(auth *AuthContext, resource *ResourceInfo, count int) error {
|
||||
|
||||
// 检查时间或配额
|
||||
if resource.Type == 1 { // 包时
|
||||
if resource.Expire.Before(time.Now()) {
|
||||
if time.Time(resource.Expire).Before(time.Now()) {
|
||||
return ChannelServiceErr("套餐已过期")
|
||||
}
|
||||
} else { // 包量
|
||||
@@ -559,6 +561,7 @@ func assignPort(
|
||||
key := uint64(channel.ProxyID)<<32 | uint64(channel.ProxyPort)
|
||||
portsMap[key] = struct{}{}
|
||||
}
|
||||
println(len(portsMap))
|
||||
|
||||
// 查找用户白名单
|
||||
var whitelist []string
|
||||
@@ -570,6 +573,9 @@ func assignPort(
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(whitelist) == 0 {
|
||||
return nil, nil, ChannelServiceErr("用户没有白名单")
|
||||
}
|
||||
}
|
||||
|
||||
// 配置启用代理
|
||||
|
||||
Reference in New Issue
Block a user