Browse Source

refactor(model): 调整 GlobalLimit 和 GatewayGroup 模型

- 在 GatewayGroup 模型中添加 BanUdp 字段- 从 GlobalLimit 模型中移除 BanUdp 字段
- 优化 GlobalLimit 服务中的 Bps 计算方式
fusu 1 month ago
parent
commit
59b27ad5b0

+ 1 - 0
internal/model/gatewaygroup.go

@@ -6,6 +6,7 @@ type GatewayGroup struct {
 	Id          int `gorm:"primary"`
 	HostId      int `gorm:"null"`
 	RuleId      int `gorm:"not null"`
+	BanUdp       int
 	Name        string `gorm:"null"`
 	Operator    int `gorm:"not null"`
 	Comment     string `gorm:"null"`

+ 0 - 1
internal/model/globallimit.go

@@ -7,7 +7,6 @@ type GlobalLimit struct {
 	HostId          int
 	RuleId          int
 	Uid             int
-	BanUdp          int
 	TcpLimitRuleId  int
 	UdpLimitRuleId  int
 	WebLimitRuleId  int

+ 2 - 2
internal/service/globallimit.go

@@ -86,7 +86,8 @@ func (s *globalLimitService) GlobalLimitRequire(ctx context.Context, req v1.Glob
 	if err != nil {
 		return v1.GlobalLimitRequireResponse{}, err
 	}
-	res.Bps = strconv.Itoa(bpsInt / 2.0 / 8.0) + "M"
+	resultFloat := float64(bpsInt) / 2.0 / 8.0
+	res.Bps = strconv.FormatFloat( resultFloat, 'f', -1, 64) + "M"
 
 	res.MaxBytesMonth = configCount.MaxBytesMonth
 	res.Operator = configCount.Operator
@@ -218,7 +219,6 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
 		HostId:          req.HostId,
 		RuleId:          cast.ToInt(ruleId),
 		Uid:             req.Uid,
-		BanUdp:          0,
 		GlobalLimitName: require.GlobalLimitName,
 		Comment:         req.Comment,
 		TcpLimitRuleId:  tcpLimitRuleId,