Skip to content
Myr

refactor(json): make jsonite optional with build tags (#1026)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* refactor(json): Restore gin support for app engine Create new folder to support multiple json package. restore gin support for app engine (disable jsonite through tags) use jsoniter $ go build -tags=jsoniter . use default json $ go build . Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * rename json file. Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * docs(json): add build tags document. * fix(docs): markdown format. * fix(json): missing space.

authored by Bo-Yi Wu · committed by Javier Provecho Fernandez · parent 7180f2b · Browse files · 7 files+47 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+47 added−9 removed

  • other:+47 added−9 removed

7 files+47 added−9 removed

modified:binding/json.go+1 added-2 removed
5 unmodified lines
67import (8 "net/http"910 "github.com/json-iterator/go"10 "github.com/gin-gonic/gin/json"11)1213var (14 json = jsoniter.ConfigCompatibleWithStandardLibrary14 EnableDecoderUseNumber = false15)1617type jsonBinding struct{}
15 unmodified lines
added:json/json.go+17 added
1// Copyright 2017 Bo-Yi Wu. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45// +build !jsoniter67package json89import (10 "encoding/json"11)1213var (14 Marshal = json.Marshal15 MarshalIndent = json.MarshalIndent16 NewDecoder = json.NewDecoder17)
added:json/jsoniter.go+18 added
1// Copyright 2017 Bo-Yi Wu. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45// +build jsoniter67package json89import (10 "github.com/json-iterator/go"11)1213var (14 json = jsoniter.ConfigCompatibleWithStandardLibrary15 Marshal = json.Marshal16 MarshalIndent = json.MarshalIndent17 NewDecoder = json.NewDecoder18)
modified:render/json.go+1 added-3 removed
6 unmodified lines
7import (8 "bytes"9 "net/http"1011 "github.com/json-iterator/go"11 "github.com/gin-gonic/gin/json"12)1314var json = jsoniter.ConfigCompatibleWithStandardLibrary1514type JSON struct {15 Data interface{}16}17
65 unmodified lines
modified:errors_test.go+1 added
6 unmodified lines
7import (8 "errors"9 "testing"1011 "github.com/gin-gonic/gin/json"12 "github.com/stretchr/testify/assert"13)1415func TestError(t *testing.T) {
91 unmodified lines
modified:errors.go+1 added-3 removed
7 unmodified lines
8 "bytes"9 "fmt"10 "reflect"1112 "github.com/json-iterator/go"12 "github.com/gin-gonic/gin/json"13)1415var json = jsoniter.ConfigCompatibleWithStandardLibrary1615type ErrorType uint641617const (18 ErrorTypeBind ErrorType = 1 << 63 // used when c.Bind() fails
139 unmodified lines
modified:README.md+8 added-1 removed
86 unmodified lines
87- [x] Complete suite of unit tests88- [x] Battle tested89- [x] API frozen, new releases will not break your code.909191## Start using it92931. Download and install it:94
44 unmodified lines
139```sh140$ go run main.go141```142143## Build with [jsoniter](https://github.com/json-iterator/go)144145Gin use `encoding/json` as default json package but you can change to [jsoniter](https://github.com/json-iterator/go) by build from other tags.146147```sh148$ go build -tags=jsoniter .149```150151## API Examples152153### Using GET, POST, PUT, PATCH, DELETE and OPTIONS154
936 unmodified lines