Skip to content

Commit 7249b9a

Browse files
committed
docs(workflow): 更新 GitHub Actions 工作流配置
- 将 Go 版本条件从 '1.23' 更改为 'stable' - 保持静态检查工具的运行条件一致 docs(strutil): 为字符串工具函数添加使用示例 - 为 ReplaceVars 函数添加使用示例代码 - 为 TextWrap 和 WidthWrap 函数添加功能说明和示例 - 明确标注 TextWrap 作为 WidthWrap 的别名 docs(group): 标记旧的错误组函数为废弃状态 - 为 NewCtxErrGroup 和 NewErrGroup 添加废弃说明 - 修复 QuickRun 中上下文键名冲突问题
1 parent f251413 commit 7249b9a

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ jobs:
3333

3434
# - name: Revive check
3535
# uses: morphy2k/revive-action@v2.5.10
36-
# if: ${{ matrix.os == 'ubuntu-latest' && matrix.go_version == '1.23' }}
36+
# if: ${{ matrix.os == 'ubuntu-latest' && matrix.go_version == 'stable' }}
3737
# with:
3838
# # Exclude patterns, separated by semicolons (optional)
3939
# exclude: "./internal/..."
4040

4141
- name: Run staticcheck
4242
uses: reviewdog/action-staticcheck@v1
43-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go_version == '1.23' }}
43+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go_version == 'stable' }}
4444
with:
4545
github_token: ${{ secrets.github_token }}
4646
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].

group.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ import (
1212
type ErrGroup = syncs.ErrGroup
1313

1414
// NewCtxErrGroup instance. use for batch run tasks, can with context.
15+
//
16+
// Deprecated: use syncs.NewCtxErrGroup instead
1517
func NewCtxErrGroup(ctx context.Context, limit ...int) (*ErrGroup, context.Context) {
1618
return syncs.NewCtxErrGroup(ctx, limit...)
1719
}
1820

1921
// NewErrGroup instance. use for batch run tasks
22+
//
23+
// Deprecated: use syncs.NewErrGroup instead
2024
func NewErrGroup(limit ...int) *ErrGroup {
2125
return syncs.NewErrGroup(limit...)
2226
}
@@ -47,7 +51,7 @@ func (p *QuickRun) Add(fns ...RunFn) *QuickRun {
4751
// Run all func
4852
func (p *QuickRun) Run() error {
4953
for i, fn := range p.fns {
50-
p.ctx.Set("index", i)
54+
p.ctx.Set("_index", i)
5155
if err := fn(p.ctx); err != nil {
5256
return err
5357
}

group_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ import (
1212
)
1313

1414
func TestNewErrGroup(t *testing.T) {
15-
httpreq.SetTimeout(3000)
16-
1715
eg := goutil.NewErrGroup()
1816
eg.Add(func() error {
1917
resp, err := httpreq.Get(testSrvAddr + "/get")
2018
if err != nil {
2119
return err
2220
}
2321

24-
fmt.Println(testutil.ParseBodyToReply(resp.Body))
25-
return nil
26-
}, func() error {
27-
resp := httpreq.MustResp(httpreq.Post(testSrvAddr+"/post", "hi"))
2822
fmt.Println(testutil.ParseBodyToReply(resp.Body))
2923
return nil
3024
})

reflects/check_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package reflects_test
22

33
import (
4+
"fmt"
45
"reflect"
56
"testing"
67
"time"
@@ -70,9 +71,18 @@ func TestIsEqual(t *testing.T) {
7071
is.True(reflects.IsEqual([]byte("abc"), []byte("abc")))
7172
is.False(reflects.IsEqual([]byte("abc"), 123))
7273

74+
/*
75+
原因
76+
变量初始化状态不同:
77+
[]string{} 是一个非零值的空切片,其长度为0,但已初始化
78+
data []string 是一个零值的切片,声明但未初始化
79+
底层实现差异:
80+
[]string{}:len=0, cap=0, ptr != nil
81+
data []string:len=0, cap=0, ptr = nil
82+
*/
7383
var data []string
74-
// fmt.Printf("%+v %+v\n", data, []string{})
7584
is.False(reflects.IsEqual([]string{}, data))
85+
fmt.Printf("%+v %+v\n", []string{}, data)
7686
}
7787

7888
// ST for testing

strutil/format.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ func Replaces(str string, pairs map[string]string) string {
198198
}
199199

200200
// ReplaceVars replaces simple variables in a string. format: {varName}
201+
//
202+
// Usage:
203+
// strutil.ReplaceVars("{name}, age is {age}", map[string]string{
204+
// "name": "Joe",
205+
// "age": "18"
206+
// })
201207
func ReplaceVars(s string, vars map[string]string) string {
202208
if !ContainsByte(s, '{') {
203209
return s

strutil/runes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,14 @@ func Utf8Split(s string, w int) []string {
180180
return ss
181181
}
182182

183-
// TextWrap a string by "\n"
183+
// TextWrap a string by "\n". alias of the WidthWrap()
184184
func TextWrap(s string, w int) string { return WidthWrap(s, w) }
185185

186186
// WidthWrap a string by "\n"
187+
//
188+
// Example:
189+
// s := "hello 你好, world 世界"
190+
// s1 := strutil.TextWrap(s, 6) // "hello \n你好, \nworld \n世界"
187191
func WidthWrap(s string, w int) string {
188192
tmpW := 0
189193
out := ""

0 commit comments

Comments
 (0)