mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 22:53:34 +08:00
As an experiment, with a thought for how Gin might eventually migrate to
and use features from jsonv2, I have put together a new json/codec for
json/v2.
---
Selected with -tags jsonv2, and constrained to go1.27 &&
goexperiment.jsonv2 since encoding/json/v2 is still gated by the
experiment in 1.27 and GOEXPERIMENT=nojsonv2 makes it unimportable.
json.go negates that entire expression, mirroring how it already
negates sonic's OS constraint, so -tags jsonv2 on Go 1.25/1.26 falls
back to encoding/json rather than leaving API nil.
Uses json.DefaultOptionsV1() to keep behaviour identical to the v1
codec: v2's native defaults would render nil slices/maps as []/{} and
match member names case-sensitively, silently zeroing fields that
previously bound.
Fills three v1 gaps v2's API doesn't cover directly: UseNumber has no
exported option, so it's reproduced with a custom *any unmarshaler;
MarshalWrite omits Encoder.Encode's trailing newline; MarshalIndent
becomes jsontext.WithIndentPrefix + WithIndent.
85 lines
2.0 KiB
YAML
85 lines
2.0 KiB
YAML
name: Run Tests
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version: "^1"
|
|
- name: Setup golangci-lint
|
|
uses: golangci/golangci-lint-action@v9
|
|
with:
|
|
version: v2.11
|
|
args: --verbose
|
|
test:
|
|
needs: lint
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, macos-latest]
|
|
go: ["1.25", "1.26", "1.27"]
|
|
test-tags:
|
|
[
|
|
"",
|
|
"-tags nomsgpack",
|
|
'--ldflags="-checklinkname=0" -tags sonic',
|
|
"-tags go_json",
|
|
"-tags jsonv2",
|
|
"-race",
|
|
]
|
|
include:
|
|
- os: ubuntu-latest
|
|
go-build: ~/.cache/go-build
|
|
- os: macos-latest
|
|
go-build: ~/Library/Caches/go-build
|
|
name: ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }}
|
|
runs-on: ${{ matrix.os }}
|
|
env:
|
|
GO111MODULE: on
|
|
TESTTAGS: ${{ matrix.test-tags }}
|
|
GOPROXY: https://proxy.golang.org
|
|
steps:
|
|
- name: Set up Go ${{ matrix.go }}
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version: ${{ matrix.go }}
|
|
cache: false
|
|
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v7
|
|
with:
|
|
ref: ${{ github.ref }}
|
|
|
|
- uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
${{ matrix.go-build }}
|
|
~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-
|
|
|
|
- name: Run Tests
|
|
run: make test
|
|
|
|
- name: Upload coverage to Codecov
|
|
uses: codecov/codecov-action@v7
|
|
with:
|
|
flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }}
|