Skip to content

Commit

Permalink
fix json sort the map keys
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed Jul 8, 2017
1 parent cb524fc commit e23842e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion binding/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package binding
import (
"net/http"

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

var json = jsoniter.ConfigCompatibleWithStandardLibrary

type jsonBinding struct{}

func (jsonBinding) Name() string {
Expand Down
2 changes: 1 addition & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func TestContextRenderIndentedJSON(t *testing.T) {
c.IndentedJSON(201, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}})

assert.Equal(t, w.Code, 201)
assert.Equal(t, "{\n \"foo\":\"bar\",\n \"bar\":\"foo\",\n \"nested\":{\n \"foo\":\"bar\"\n }\n}", w.Body.String())
assert.Equal(t, "{\n \"bar\":\"foo\",\n \"foo\":\"bar\",\n \"nested\":{\n \"foo\":\"bar\"\n }\n}", w.Body.String())
assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type"))
}

Expand Down
4 changes: 3 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"fmt"
"reflect"

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

var json = jsoniter.ConfigCompatibleWithStandardLibrary

type ErrorType uint64

const (
Expand Down
5 changes: 2 additions & 3 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"testing"

json "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
)

Expand All @@ -32,7 +31,7 @@ func TestError(t *testing.T) {
})

jsonBytes, _ := json.Marshal(err)
assert.Equal(t, "{\"meta\":\"some data\",\"error\":\"test error\"}", string(jsonBytes))
assert.Equal(t, "{\"error\":\"test error\",\"meta\":\"some data\"}", string(jsonBytes))

err.SetMeta(H{
"status": "200",
Expand Down Expand Up @@ -91,7 +90,7 @@ Error #03: third
H{"error": "third", "status": "400"},
})
jsonBytes, _ := json.Marshal(errs)
assert.Equal(t, "[{\"error\":\"first\"},{\"meta\":\"some data\",\"error\":\"second\"},{\"status\":\"400\",\"error\":\"third\"}]", string(jsonBytes))
assert.Equal(t, "[{\"error\":\"first\"},{\"error\":\"second\",\"meta\":\"some data\"},{\"error\":\"third\",\"status\":\"400\"}]", string(jsonBytes))
errs = errorMsgs{
{Err: errors.New("first"), Type: ErrorTypePrivate},
}
Expand Down
4 changes: 3 additions & 1 deletion render/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"bytes"
"net/http"

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

var json = jsoniter.ConfigCompatibleWithStandardLibrary

type JSON struct {
Data interface{}
}
Expand Down

0 comments on commit e23842e

Please sign in to comment.