Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

Commit

Permalink
refactor: update cod version
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Jul 11, 2019
1 parent 92a9949 commit 8421dc0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/stretchr/testify v1.3.0
github.com/vicanso/cod v0.1.3
github.com/vicanso/hes v0.1.4
github.com/vicanso/cod v0.1.5
github.com/vicanso/hes v0.2.1
)
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/vicanso/cod v0.1.3 h1:M0yGEQ7bXWHfw961rC+sgJoIwFqvZldalnSQTWTqf6I=
github.com/vicanso/cod v0.1.3/go.mod h1:T5GOazXuYrwwE1qMA0G3zka7NVwwkoL2fYIWNfeEpJw=
github.com/vicanso/hes v0.1.4 h1:n8kG8krvNJF4Sj1PvZOEUzdUsmDSbCcGr8C1nYnoP+o=
github.com/vicanso/cod v0.1.5 h1:KqdTAo1TzUa+iYbdzg1INEAZCG4pvxHkwmwKac5RLz8=
github.com/vicanso/cod v0.1.5/go.mod h1:T5GOazXuYrwwE1qMA0G3zka7NVwwkoL2fYIWNfeEpJw=
github.com/vicanso/hes v0.1.4/go.mod h1:bG0UJ3EihDKObFcLLwJYjxHHr9saFllsFcepyDIvFlo=
github.com/vicanso/hes v0.2.1 h1:jRFEADmiQ30koVY/sKwlkhyXM5B3QbVVizLqrjNJgPw=
github.com/vicanso/hes v0.2.1/go.mod h1:QcxOFmFfBQMhASTaLgnFayXYCgevdSeBVprt+o+3eKo=
github.com/vicanso/keygrip v0.1.0 h1:/zYzoVIbREAvaxSM7bo3/oSXuuYztaP71dPBfhRoNkM=
github.com/vicanso/keygrip v0.1.0/go.mod h1:cI05iOjY00NJ7oH2Z9Zdm9eJPUkpoex3XnEubK78nho=
4 changes: 2 additions & 2 deletions responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ func New(config Config) cod.Handler {
// 转换为json
buf, err := marshal(c.Body)
if err != nil {
c.Cod(nil).EmitError(c, err)
c.Cod().EmitError(c, err)
statusCode = http.StatusInternalServerError
he := hes.NewWithErrorStatusCode(err, statusCode)
he.Exception = true
c.SetHeader(ct, cod.MIMEApplicationJSON)
body, _ = marshal(he)
body = he.ToJSON()
err = nil
} else {
if !hadContentType {
Expand Down
5 changes: 4 additions & 1 deletion responder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func TestResponder(t *testing.T) {
})

t.Run("json marshal fail", func(t *testing.T) {
assert := assert.New(t)
d := cod.New()
d.Use(m)
d.GET("/", func(c *cod.Context) error {
Expand All @@ -148,7 +149,9 @@ func TestResponder(t *testing.T) {
})
resp := httptest.NewRecorder()
d.ServeHTTP(resp, req)
checkResponse(t, resp, 500, `{"statusCode":500,"message":"func() is unsupported type","exception":true}`)
assert.Equal(500, resp.Code)
fmt.Println(resp.Body.String())
assert.True(strings.HasSuffix(resp.Body.String(), `"statusCode":500,"message":"func() is unsupported type","exception":true}`))
})

t.Run("reader body", func(t *testing.T) {
Expand Down

0 comments on commit 8421dc0

Please sign in to comment.