Sfoglia il codice sorgente

feat(gameShield): 调整最大带宽默认值并优化数据处理

- 将最大带宽默认值从 50m调整为 100m
- 使用 pointer 库处理 MaxBandwidth 字段,提高代码可读性和安全性
- 优化数据转换和验证逻辑
-引入新的依赖库并移除未使用的库
fusu 2 mesi fa
parent
commit
0a15ce2d5e
5 ha cambiato i file con 12 aggiunte e 10 eliminazioni
  1. 1 1
      api/v1/gameShieldBackend.go
  2. 2 2
      go.mod
  3. 2 2
      go.sum
  4. 4 4
      internal/service/formatter.go
  5. 3 1
      internal/service/gameshieldbackend.go

+ 1 - 1
api/v1/gameShieldBackend.go

@@ -12,7 +12,7 @@ type GameShieldBackendRequest struct {
 	SdkPort         string    `json:"sdk_port" form:"sdk_port"`
 	SdkIp           string    `json:"sdk_ip" form:"sdk_ip"`
 	Type            string    `json:"type" form:"type"`
-	MaxBandwidth    int       `json:"max_bandwidth" form:"max_bandwidth"`
+	MaxBandwidth    *int      `json:"max_bandwidth" form:"max_bandwidth"`
 	Checked         string    `json:"checked" form:"checked"`
 	CreatedAt       time.Time `json:"created_at" form:"created_at"`
 	UpdatedAt       time.Time `json:"updated_at" form:"updated_at"`

+ 2 - 2
go.mod

@@ -5,8 +5,10 @@ go 1.23.0
 toolchain go1.24.1
 
 require (
+	github.com/AlekSi/pointer v1.2.0
 	github.com/DATA-DOG/go-sqlmock v1.5.2
 	github.com/PuerkitoBio/goquery v1.10.3
+	github.com/davecgh/go-spew v1.1.1
 	github.com/duke-git/lancet/v2 v2.3.5
 	github.com/gavv/httpexpect/v2 v2.16.0
 	github.com/gin-gonic/gin v1.9.1
@@ -18,7 +20,6 @@ require (
 	github.com/mcuadros/go-defaults v1.2.0
 	github.com/redis/go-redis/v9 v9.0.5
 	github.com/sony/sonyflake v1.1.0
-	github.com/sourcegraph/conc v0.3.0
 	github.com/spf13/cast v1.5.1
 	github.com/spf13/viper v1.8.1
 	github.com/stretchr/testify v1.8.4
@@ -45,7 +46,6 @@ require (
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
 	github.com/chenzhuoyu/iasm v0.9.0 // indirect
-	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
 	github.com/dustin/go-humanize v1.0.1 // indirect
 	github.com/fatih/color v1.15.0 // indirect

+ 2 - 2
go.sum

@@ -40,6 +40,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
 cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
+github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w=
+github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
@@ -396,8 +398,6 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/sony/sonyflake v1.1.0 h1:wnrEcL3aOkWmPlhScLEGAXKkLAIslnBteNUq4Bw6MM4=
 github.com/sony/sonyflake v1.1.0/go.mod h1:LORtCywH/cq10ZbyfhKrHYgAUGH7mOBa76enV9txy/Y=
-github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
-github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
 github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
 github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
 github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=

+ 4 - 4
internal/service/formatter.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+	"github.com/AlekSi/pointer"
 	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
 	"github.com/go-nunu/nunu-layout-advanced/internal/model"
 	"github.com/go-nunu/nunu-layout-advanced/internal/repository"
@@ -120,7 +121,7 @@ func (service *formatterService) OldFormat(ctx context.Context, req *[]model.Gam
 			v.SdkIp = ""
 		}
 		if v.MaxBandwidth == 1 {
-			MaxBandwidth = "50m"
+			MaxBandwidth = "100m"
 		} else {
 			MaxBandwidth = ""
 		}
@@ -199,8 +200,8 @@ func (service *formatterService) TidyFormatBackendData(ctx context.Context, req
 				itemMap.SdkIp = item.SdkIp
 			}
 
-			if item.MaxBandwidth == 1 {
-				itemMap.MaxBandwidth = "50m"
+			if pointer.GetInt(item.MaxBandwidth) == 1 {
+				itemMap.MaxBandwidth = "100m"
 			} else {
 				itemMap.MaxBandwidth = ""
 			}
@@ -266,7 +267,6 @@ func (service *formatterService) ValidateBackendData(ctx context.Context, data m
 				sourceIPs[parts[0]] = true
 			}
 		}
-
 		// 计算最大带宽设置数
 		if item.MaxBandwidth != "" {
 			maxBandwidthCount++

+ 3 - 1
internal/service/gameshieldbackend.go

@@ -3,6 +3,7 @@ package service
 import (
 	"context"
 	"fmt"
+	"github.com/AlekSi/pointer"
 	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
 	"github.com/go-nunu/nunu-layout-advanced/internal/model"
 	"github.com/go-nunu/nunu-layout-advanced/internal/repository"
@@ -207,7 +208,8 @@ func (s *gameShieldBackendService) EditGameShieldBackend(ctx context.Context, re
 		simulatedData[idx].SdkPort = v.SdkPort
 		simulatedData[idx].SdkIp = v.SdkIp
 		simulatedData[idx].Type = v.Type
-		simulatedData[idx].MaxBandwidth = v.MaxBandwidth
+		//获取指针的值
+		simulatedData[idx].MaxBandwidth = pointer.GetInt(v.MaxBandwidth)
 	}
 	// 5. 使用模拟修改后的数据进行验证
 	// 转换数据格式