Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt add-json-iterator-with-build-tags #11

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ script:
- go get -d -t ./...
- go test ./...
- >
goimports -d -e ./ | grep '.*' && { echo; echo "Aborting due to non-empty goimports output."; exit 1; } || :
goimports -d -e $(find ./* -type f -name '*.go' | grep -v 'jsoniter') | grep '.*' && { echo; echo "Aborting due to non-empty goimports output."; exit 1; } || :
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ example which uses the latest chi/render sub-pkg.

All feedback is welcome, thank you!

## Build with [jsoniter](https://github.com/json-iterator/go)

The `render` package use `encoding/json` as default json package but you can change to [jsoniter](https://github.com/json-iterator/go) by build from other tags.

```sh
$ go build -tags=jsoniter .
```
3 changes: 2 additions & 1 deletion decoder.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package render

import (
"encoding/json"
"encoding/xml"
"errors"
"io"
"io/ioutil"
"net/http"

"github.com/go-chi/render/json"
)

// Decode is a package-level variable set to our default Decoder. We do this
Expand Down
11 changes: 11 additions & 0 deletions json/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !jsoniter

package json

import "encoding/json"

var (
Marshal = json.Marshal
NewDecoder = json.NewDecoder
NewEncoder = json.NewEncoder
)
12 changes: 12 additions & 0 deletions json/jsoniter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build jsoniter

package json

import "github.com/json-iterator/go"

var (
json = jsoniter.ConfigCompatibleWithStandardLibrary
Marshal = json.Marshal
NewDecoder = json.NewDecoder
NewEncoder = json.NewEncoder
)
3 changes: 2 additions & 1 deletion responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package render
import (
"bytes"
"context"
"encoding/json"
"encoding/xml"
"fmt"
"net/http"
"reflect"

"github.com/go-chi/render/json"
)

// M is a convenience alias for quickly building a map structure that is going
Expand Down