Skip to content

Commit 5b844bd

Browse files
lvan100lianghuan
authored andcommitted
chore(ci): GOEXPERIMENT=jsonv2
1 parent 8b055fb commit 5b844bd

13 files changed

Lines changed: 327 additions & 43 deletions

File tree

.github/workflows/lint.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ jobs:
1010
lint:
1111
name: Run golangci-lint
1212
runs-on: ubuntu-latest
13+
14+
env:
15+
GOEXPERIMENT: jsonv2
16+
1317
steps:
1418
- name: Checkout code
15-
uses: actions/checkout@v4
19+
uses: actions/checkout@v6.0.2
1620

1721
- name: Print All environment variables
1822
run: env | sort
1923

2024
- name: Set up Go
21-
uses: actions/setup-go@v5
25+
uses: actions/setup-go@v6.3.0
26+
with:
27+
go-version: '1.25'
2228

2329
- name: Install golangci-lint
24-
uses: golangci/golangci-lint-action@v7
30+
uses: golangci/golangci-lint-action@v9.2.0
2531
with:
2632
version: latest
2733

.github/workflows/test.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ jobs:
1010
test:
1111
name: Run tests and collect coverage
1212
runs-on: ubuntu-latest
13+
14+
env:
15+
GOEXPERIMENT: jsonv2
16+
1317
steps:
1418
- name: Checkout
15-
uses: actions/checkout@v4
19+
uses: actions/checkout@v6.0.2
1620

1721
- name: Print All environment variables
1822
run: env | sort
1923

2024
- name: Set up Go
21-
uses: actions/setup-go@v5
25+
uses: actions/setup-go@v6.3.0
26+
with:
27+
go-version: '1.25'
2228

2329
- name: Install dependencies
2430
run: go mod download
@@ -27,7 +33,7 @@ jobs:
2733
run: go test -count=1 -coverprofile=coverage.txt ./...
2834

2935
- name: Upload results to Codecov
30-
uses: codecov/codecov-action@v5
36+
uses: codecov/codecov-action@v5.5.2
3137
with:
3238
token: ${{ secrets.CODECOV_TOKEN }}
33-
slug: go-spring/stdlib
39+
slug: go-spring/stdlib

funcutil/funcutil_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ func TestFuncName(t *testing.T) {
3333
assert.That(t, funcutil.FuncName((*receiver).ptrFnWithArgs)).Equal("funcutil_test.(*receiver).ptrFnWithArgs")
3434
}
3535

36+
// nolint: unused
3637
func fnNoArgs() {}
3738

39+
// nolint: unused
3840
func fnWithArgs(i int) {}
3941

4042
type receiver struct{}
4143

44+
// nolint: unused
4245
func (r *receiver) ptrFnNoArgs() {}
4346

47+
// nolint: unused
4448
func (r *receiver) ptrFnWithArgs(i int) {}
4549

4650
func TestFileLine(t *testing.T) {
@@ -53,25 +57,25 @@ func TestFileLine(t *testing.T) {
5357
{
5458
fnNoArgs,
5559
"funcutil/funcutil_test.go",
56-
36,
60+
37,
5761
"funcutil_test.fnNoArgs",
5862
},
5963
{
6064
fnWithArgs,
6165
"funcutil/funcutil_test.go",
62-
38,
66+
40,
6367
"funcutil_test.fnWithArgs",
6468
},
6569
{
6670
(*receiver).ptrFnNoArgs,
6771
"funcutil/funcutil_test.go",
68-
42,
72+
45,
6973
"funcutil_test.(*receiver).ptrFnNoArgs",
7074
},
7175
{
7276
(*receiver).ptrFnWithArgs,
7377
"funcutil/funcutil_test.go",
74-
44,
78+
48,
7579
"funcutil_test.(*receiver).ptrFnWithArgs",
7680
},
7781
}

goutil/goutil_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func TestGoValue(t *testing.T) {
173173
t.Run("context value inheritance with withoutCancel", func(t *testing.T) {
174174
key := "test_key"
175175
value := "test_value"
176+
// nolint: staticcheck
176177
ctx := context.WithValue(context.Background(), key, value)
177178
ctx, cancel := context.WithCancel(ctx)
178179
cancel()

httpclt/httpclt_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ func (r *HelloResponse) DecodeJSON(d jsonflow.Decoder) (err error) {
7272
return err
7373
}
7474

75-
for {
76-
if d.PeekKind() == '}' {
77-
break
78-
}
75+
for d.PeekKind() != '}' {
7976

8077
var key string
8178
key, err = jsonflow.DecodeString(d)
@@ -112,6 +109,7 @@ func (c *HelloClient) Hello(ctx context.Context, req *HelloRequest, opts ...http
112109
Schema: "http",
113110
Method: "GET",
114111
Pattern: "/v1/hello",
112+
// nolint: staticcheck
115113
RawPath: fmt.Sprintf("/v1/hello"),
116114
Query: req,
117115
Header: http.Header{

httpsvr/httpsvr_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewHelloRequest() *HelloRequest {
4545
func (x *HelloRequest) Bind(r *http.Request) (err error) {
4646
values, parseErr := url.ParseQuery(r.URL.RawQuery)
4747
if parseErr != nil {
48-
err = errutil.Explain(err, "parse query error: %w", parseErr)
48+
err = errutil.Explain(err, "parse query error: %s", parseErr)
4949
return
5050
}
5151

@@ -58,7 +58,7 @@ func (x *HelloRequest) Bind(r *http.Request) (err error) {
5858
if len(v) == 1 {
5959
x.Message = v[0]
6060
} else {
61-
err = errutil.Stack(err, "invalid value for \"message\"")
61+
err = errutil.Explain(err, "invalid value for \"message\"")
6262
}
6363
}
6464
if !hasMessage {
@@ -69,7 +69,7 @@ func (x *HelloRequest) Bind(r *http.Request) (err error) {
6969

7070
func (x *HelloRequest) Validate() (err error) {
7171
if validateErr := x.HelloRequestBody.Validate(); validateErr != nil {
72-
err = errutil.Stack(err, "validate failed on \"HelloRequest\": %w", validateErr)
72+
err = errutil.Stack(err, "validate failed on \"HelloRequest\": %s", validateErr)
7373
}
7474
return
7575
}
@@ -82,10 +82,7 @@ func (x *HelloRequestBody) DecodeJSON(d jsonflow.Decoder) (err error) {
8282
return err
8383
}
8484

85-
for {
86-
if d.PeekKind() == '}' {
87-
break
88-
}
85+
for d.PeekKind() != '}' {
8986

9087
var key string
9188
key, err = jsonflow.DecodeString(d)
@@ -172,9 +169,9 @@ func TestHello(t *testing.T) {
172169
if err != nil {
173170
panic(err)
174171
}
175-
resp.Body.Close()
172+
_ = resp.Body.Close()
176173
fmt.Println(string(b))
177-
svr.Shutdown(t.Context())
174+
_ = svr.Shutdown(t.Context())
178175
}
179176

180177
func TestStream(t *testing.T) {
@@ -195,7 +192,7 @@ func TestStream(t *testing.T) {
195192
if err != nil {
196193
panic(err)
197194
}
198-
resp.Body.Close()
195+
_ = resp.Body.Close()
199196
fmt.Print(string(b))
200-
svr.Shutdown(t.Context())
197+
_ = svr.Shutdown(t.Context())
201198
}

iterutil/iterutil_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ func BenchmarkRanges(b *testing.B) {
3737

3838
b.Run("for", func(b *testing.B) {
3939
for b.Loop() {
40-
fibonacci(N)
40+
_ = fibonacci(N)
4141
}
4242
})
4343

4444
b.Run("loop", func(b *testing.B) {
4545
for b.Loop() {
4646
Times(5, func(i int) {
47-
fibonacci(N)
47+
_ = fibonacci(N)
4848
})
4949
}
5050
})

jsonflow/decode.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,7 @@ func DecodeArray[T any](
335335
case '[':
336336
_, _, _ = d.ReadToken()
337337
v := make([]T, 0)
338-
for {
339-
if d.PeekKind() == ']' {
340-
break
341-
}
338+
for d.PeekKind() != ']' {
342339
i, err := parseFn(d)
343340
if err != nil {
344341
return nil, err
@@ -372,10 +369,7 @@ func DecodeMap[K comparable, V any](
372369
case '{':
373370
_, _, _ = d.ReadToken()
374371
m := make(map[K]V)
375-
for {
376-
if d.PeekKind() == '}' {
377-
break
378-
}
372+
for d.PeekKind() != '}' {
379373
key, err := parseKeyFn(d)
380374
if err != nil {
381375
return nil, err

jsonflow/decode_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,7 @@ func (b *TestObject) DecodeJSON(d Decoder) error {
862862
foundInt bool
863863
)
864864

865-
for {
866-
if d.PeekKind() == '}' {
867-
break
868-
}
865+
for d.PeekKind() != '}' {
869866
key, err := DecodeString(d)
870867
if err != nil {
871868
return err

mathutil/overflow.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func OverflowInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](v int64) bool {
3333
case int32:
3434
return v > math.MaxInt32 || v < math.MinInt32
3535
case int64:
36-
return v > math.MaxInt64 || v < math.MinInt64
3736
}
3837
return false
3938
}

0 commit comments

Comments
 (0)