diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2e103caf..ac3e0390 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,7 +24,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: 1.25.1 - name: Lint Go Code run: | @@ -45,7 +45,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: 1.25.1 - name: Run Unit tests run: make test @@ -73,7 +73,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: 1.25.1 - name: Build run: make build && make build-sponge diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37339c4d..c67e1df9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: 1.25.1 - name: Create release on GitHub uses: goreleaser/goreleaser-action@v3 diff --git a/cmd/sponge/commands/perftest/common/progress_bar.go b/cmd/sponge/commands/perftest/common/progress_bar.go index d156fead..7e4dc456 100644 --- a/cmd/sponge/commands/perftest/common/progress_bar.go +++ b/cmd/sponge/commands/perftest/common/progress_bar.go @@ -147,8 +147,7 @@ func NewTimeBar(totalDuration time.Duration) *TimeBar { // Start begins automatic updates in a background goroutine. func (b *TimeBar) Start() { b.startTime = time.Now() - b.wg.Add(1) - go b.run() + b.wg.Go(func() { b.run() }) } // stopped is an internal helper to handle shutting down the progress bar. @@ -178,8 +177,6 @@ func (b *TimeBar) Stop() { // run periodically refreshes the bar in the background. func (b *TimeBar) run() { - defer b.wg.Done() - ticker := time.NewTicker(500 * time.Millisecond) defer ticker.Stop() diff --git a/cmd/sponge/commands/perftest/http/run.go b/cmd/sponge/commands/perftest/http/run.go index 5b693940..795e99c8 100644 --- a/cmd/sponge/commands/perftest/http/run.go +++ b/cmd/sponge/commands/perftest/http/run.go @@ -125,14 +125,12 @@ func (p *PerfTestHTTP) RunWithFixedRequestsNum(globalCtx context.Context) (*Stat } for i := 0; i < p.Worker; i++ { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for range jobs { requestOnce(p.Client, p.Params, resultCh) bar.Increment() } - }() + }) } start = time.Now() @@ -214,19 +212,17 @@ func (p *PerfTestHTTP) RunWithFixedDuration(globalCtx context.Context) (*Statist // Start workers for i := 0; i < p.Worker; i++ { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { // Keep sending requests until the context is canceled for { select { case <-ctx.Done(): - return // Exit goroutine when context is canceled + return default: requestOnce(p.Client, p.Params, resultCh) } } - }() + }) } start = time.Now() diff --git a/cmd/sponge/commands/perftest/websocket/client.go b/cmd/sponge/commands/perftest/websocket/client.go index 90fbf2ec..34d04758 100644 --- a/cmd/sponge/commands/perftest/websocket/client.go +++ b/cmd/sponge/commands/perftest/websocket/client.go @@ -61,9 +61,7 @@ func (c *Client) Dial(ctx context.Context) error { } // Run starts the client worker. -func (c *Client) Run(ctx context.Context, wg *sync.WaitGroup) { - defer wg.Done() - +func (c *Client) Run(ctx context.Context) { err := c.Dial(ctx) if err != nil { return diff --git a/cmd/sponge/commands/perftest/websocket/websocket.go b/cmd/sponge/commands/perftest/websocket/websocket.go index 36ff31d4..7490b852 100644 --- a/cmd/sponge/commands/perftest/websocket/websocket.go +++ b/cmd/sponge/commands/perftest/websocket/websocket.go @@ -149,9 +149,8 @@ func (p *perfTestParams) run() error { break } - wg.Add(1) client := NewClient(i+1, p.targetURL, stats, p.sendInterval, p.payloadData, p.isJSON) - go client.Run(mainCtx, &wg) + wg.Go(func() { client.Run(mainCtx) }) if rampUpDelay > 0 { time.Sleep(rampUpDelay) diff --git a/cmd/sponge/commands/plugins.go b/cmd/sponge/commands/plugins.go index 786870ba..667327e0 100644 --- a/cmd/sponge/commands/plugins.go +++ b/cmd/sponge/commands/plugins.go @@ -148,10 +148,9 @@ func installPlugins(lackNames []string) { continue } - wg.Add(1) - go func(name string) { - defer wg.Done() - ctx, _ := context.WithTimeout(context.Background(), time.Minute*3) //nolint + wg.Go(func() { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute*3) + defer cancel() pkgAddr, ok := installPluginCommands[name] if !ok { return @@ -166,7 +165,7 @@ func installPlugins(lackNames []string) { } else { fmt.Printf("%s %s\n", installedSymbol, name) } - }(name) + }) } wg.Wait() diff --git a/go.mod b/go.mod index 29ee9f8d..9143e4c3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/go-dev-frame/sponge -go 1.23.0 +go 1.25.0 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 diff --git a/pkg/aicli/chatgpt/client_test.go b/pkg/aicli/chatgpt/client_test.go index 4dd0c964..f868f374 100644 --- a/pkg/aicli/chatgpt/client_test.go +++ b/pkg/aicli/chatgpt/client_test.go @@ -46,7 +46,7 @@ func TestClient_SendStream(t *testing.T) { ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) reply := client.SendStream(ctx, "Which model did you use to answer the question?") for content := range reply.Content { - fmt.Printf(content) + fmt.Print(content) } if reply.Err != nil { t.Log(reply.Err) diff --git a/pkg/aicli/deepseek/client_test.go b/pkg/aicli/deepseek/client_test.go index 315e6eae..37bdcfb8 100644 --- a/pkg/aicli/deepseek/client_test.go +++ b/pkg/aicli/deepseek/client_test.go @@ -46,7 +46,7 @@ func TestClient_SendStream(t *testing.T) { ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) answer := client.SendStream(ctx, genericRoleDescZH) for content := range answer.Content { - fmt.Printf(content) + fmt.Print(content) } if answer.Err != nil { t.Log(answer.Err) diff --git a/pkg/aicli/gemini/client_test.go b/pkg/aicli/gemini/client_test.go index 82d2cd2a..153d3d0f 100644 --- a/pkg/aicli/gemini/client_test.go +++ b/pkg/aicli/gemini/client_test.go @@ -41,7 +41,7 @@ func TestClient_SendStream(t *testing.T) { ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) reply := client.SendStream(ctx, "Which model did you use to answer the question?") for content := range reply.Content { - fmt.Printf(content) + fmt.Print(content) } if reply.Err != nil { t.Log(reply.Err) diff --git a/pkg/conf/parse_test.go b/pkg/conf/parse_test.go index f59a457b..a55b238a 100644 --- a/pkg/conf/parse_test.go +++ b/pkg/conf/parse_test.go @@ -27,10 +27,10 @@ func Test_hideSensitiveFields(t *testing.T) { keywords = append(keywords, `"dsn"`, `"password"`, `"name"`) str := Show(c, keywords...) - fmt.Printf(hideSensitiveFields(str)) + fmt.Print(hideSensitiveFields(str)) str = "\ndefault:123456@192.168.3.37:6379/0\n" - fmt.Printf(hideSensitiveFields(str)) + fmt.Print(hideSensitiveFields(str)) } // test listening for configuration file updates diff --git a/pkg/gobash/gobash_test.go b/pkg/gobash/gobash_test.go index 2ae5c091..40c26ada 100644 --- a/pkg/gobash/gobash_test.go +++ b/pkg/gobash/gobash_test.go @@ -25,7 +25,7 @@ func TestRun(t *testing.T) { t.Logf("pid: %d", pid) continue } - t.Logf(v) + t.Log(v) } if result.Err != nil { t.Logf("execute command failed, %v", result.Err) diff --git a/pkg/gocrypto/wcipher/mode.go b/pkg/gocrypto/wcipher/mode.go index e1ae3fcb..3f247c7e 100644 --- a/pkg/gocrypto/wcipher/mode.go +++ b/pkg/gocrypto/wcipher/mode.go @@ -68,17 +68,20 @@ func (cbc *cbcCipherModel) Cipher(block cipher.Block, iv []byte) Cipher { return NewBlockCipher(cbc.padding, encrypter, decrypter) } -type cfbCipherModel cipherMode //nolint +type cfbCipherModel struct { + cipherMode +} // NewCFBMode new cfb mode func NewCFBMode() CipherMode { - return &ofbCipherModel{} + return &cfbCipherModel{} } // Cipher cfb cipher func (cfb *cfbCipherModel) Cipher(block cipher.Block, iv []byte) Cipher { //nolint - encrypter := cipher.NewCFBEncrypter(block, iv) - decrypter := cipher.NewCFBDecrypter(block, iv) + // CFB is deprecated; prefer CTR (unauthenticated stream) or AEAD + encrypter := cipher.NewCTR(block, iv) + decrypter := cipher.NewCTR(block, iv) return NewStreamCipher(encrypter, decrypter) } @@ -93,8 +96,9 @@ func NewOFBMode() CipherMode { // Cipher ofb cipher func (ofb *ofbCipherModel) Cipher(block cipher.Block, iv []byte) Cipher { - encrypter := cipher.NewOFB(block, iv) - decrypter := cipher.NewOFB(block, iv) + // OFB is deprecated; prefer CTR (unauthenticated stream) or AEAD + encrypter := cipher.NewCTR(block, iv) + decrypter := cipher.NewCTR(block, iv) return NewStreamCipher(encrypter, decrypter) }