File tree Expand file tree Collapse file tree 6 files changed +29
-11
lines changed
Expand file tree Collapse file tree 6 files changed +29
-11
lines changed Original file line number Diff line number Diff 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].
Original file line number Diff line number Diff line change @@ -12,11 +12,15 @@ import (
1212type ErrGroup = syncs.ErrGroup
1313
1414// NewCtxErrGroup instance. use for batch run tasks, can with context.
15+ //
16+ // Deprecated: use syncs.NewCtxErrGroup instead
1517func 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
2024func 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
4852func (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 }
Original file line number Diff line number Diff line change @@ -12,19 +12,13 @@ import (
1212)
1313
1414func 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 })
Original file line number Diff line number Diff line change 11package reflects_test
22
33import (
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
Original file line number Diff line number Diff 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+ // })
201207func ReplaceVars (s string , vars map [string ]string ) string {
202208 if ! ContainsByte (s , '{' ) {
203209 return s
Original file line number Diff line number Diff 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()
184184func 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世界"
187191func WidthWrap (s string , w int ) string {
188192 tmpW := 0
189193 out := ""
You can’t perform that action at this time.
0 commit comments