From 1d4423f56b83f7b02588762e34adb606ac3f7fd9 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 20 Feb 2026 11:17:00 +0300 Subject: [PATCH 1/3] go.mod: upgrade to Go 1.25+, fix #20 Signed-off-by: Roman Khimov --- .github/workflows/run_tests.yml | 10 +++++----- go.mod | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index c554f77..85f4841 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -27,7 +27,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.25 + go-version: 1.26 - name: Write coverage profile run: go test -v ./... -coverprofile=./coverage.txt -covermode=atomic @@ -44,17 +44,17 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go_versions: [ '1.24', '1.25' ] + go_versions: [ '1.25', '1.26' ] os: [ubuntu-latest, windows-latest, macos-latest] exclude: # Only latest Go version for Windows and MacOS. - os: windows-latest - go_versions: '1.24' + go_versions: '1.25' - os: macos-latest - go_versions: '1.24' + go_versions: '1.25' # Exclude latest Go version for Ubuntu as Coverage uses it. - os: ubuntu-latest - go_versions: '1.25' + go_versions: '1.26' fail-fast: false steps: - uses: actions/checkout@v4 diff --git a/go.mod b/go.mod index 627d352..4723659 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/nspcc-dev/go-ordered-json -go 1.24 +go 1.25 From d824a6e27ee71aa35786d3afef1d4c61a85d92b5 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 20 Feb 2026 11:20:33 +0300 Subject: [PATCH 2/3] *: use reflect.TypeAssert for more efficient casts Signed-off-by: Roman Khimov --- decode.go | 4 ++-- encode.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/decode.go b/decode.go index 3b4b375..e88ad87 100644 --- a/decode.go +++ b/decode.go @@ -461,11 +461,11 @@ func (d *decodeState) indirect(v reflect.Value, decodingNull bool) (Unmarshaler, v.Set(reflect.New(v.Type().Elem())) } if v.Type().NumMethod() > 0 { - if u, ok := v.Interface().(Unmarshaler); ok { + if u, ok := reflect.TypeAssert[Unmarshaler](v); ok { return u, nil, reflect.Value{} } if !decodingNull { - if u, ok := v.Interface().(encoding.TextUnmarshaler); ok { + if u, ok := reflect.TypeAssert[encoding.TextUnmarshaler](v); ok { return nil, u, reflect.Value{} } } diff --git a/encode.go b/encode.go index a45ffd9..5d44066 100644 --- a/encode.go +++ b/encode.go @@ -445,7 +445,7 @@ func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString("null") return } - m, ok := v.Interface().(Marshaler) + m, ok := reflect.TypeAssert[Marshaler](v) if !ok { e.WriteString("null") return @@ -466,7 +466,7 @@ func addrMarshalerEncoder(e *encodeState, v reflect.Value, _ encOpts) { e.WriteString("null") return } - m := va.Interface().(Marshaler) + m, _ := reflect.TypeAssert[Marshaler](va) b, err := m.MarshalJSON() if err == nil { // copy JSON into buffer, checking validity. @@ -482,7 +482,7 @@ func textMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString("null") return } - m := v.Interface().(encoding.TextMarshaler) + m, _ := reflect.TypeAssert[encoding.TextMarshaler](v) b, err := m.MarshalText() if err != nil { e.error(&MarshalerError{v.Type(), err}) @@ -496,7 +496,7 @@ func addrTextMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString("null") return } - m := va.Interface().(encoding.TextMarshaler) + m, _ := reflect.TypeAssert[encoding.TextMarshaler](va) b, err := m.MarshalText() if err != nil { e.error(&MarshalerError{v.Type(), err}) @@ -714,7 +714,7 @@ func orderedObjectEncoder(e *encodeState, v reflect.Value, opts encOpts) { return } e.WriteByte('{') - var ov = v.Interface().(OrderedObject) + var ov, _ = reflect.TypeAssert[OrderedObject](v) for i, o := range ov { if i > 0 { e.WriteByte(',') @@ -885,7 +885,7 @@ func (w *reflectWithString) resolve() error { w.s = w.v.String() return nil } - if tm, ok := w.v.Interface().(encoding.TextMarshaler); ok { + if tm, ok := reflect.TypeAssert[encoding.TextMarshaler](w.v); ok { buf, err := tm.MarshalText() w.s = string(buf) return err From 491b46ec6855dc35151f263d0124d561dffa7fb6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 20 Feb 2026 11:33:24 +0300 Subject: [PATCH 3/3] *: ignore new staticcheck warnings for tests These things are done on purpose. Signed-off-by: Roman Khimov --- decode_test.go | 2 +- tagkey_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/decode_test.go b/decode_test.go index 2e5ef37..f569225 100644 --- a/decode_test.go +++ b/decode_test.go @@ -1890,7 +1890,7 @@ func TestUnmarshalSyntax(t *testing.T) { type unexportedFields struct { Name string m map[string]any `json:"-"` //nolint:unused // Not really used, but important for test. - m2 map[string]any `json:"abcd"` //nolint:unused,govet // Not really used and wrong, but important for test. + m2 map[string]any `json:"abcd"` //nolint:unused,govet,staticcheck // Not really used and wrong, but important for test. } func TestUnmarshalUnexported(t *testing.T) { diff --git a/tagkey_test.go b/tagkey_test.go index cfd7dc2..b388844 100644 --- a/tagkey_test.go +++ b/tagkey_test.go @@ -45,7 +45,7 @@ type punctuationTag struct { } type dashTag struct { - V string `json:"-,"` + V string `json:"-,"` // nolint:staticcheck // The test is written this way } type emptyTag struct {