Skip to content

Commit

Permalink
improve decoder performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lixizan committed Mar 25, 2022
1 parent 567353a commit 686790f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hasaki
import "testing"

func TestNewRequest(t *testing.T) {
const baseurl = "http://localhost:8080"
const baseurl = "http://localhost:9000"
if _, err := Get(baseurl + "/p1").Send(nil).GetBody(); err != nil {
t.Error(err.Error())
}
Expand Down
10 changes: 1 addition & 9 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func (c *Response) GetBody() ([]byte, error) {
if c.Response == nil {
return nil, errors.New("response is nil")
}

defer c.Body.Close()

return ioutil.ReadAll(c.Body)
}

Expand All @@ -46,11 +44,5 @@ func (c *Response) BindJSON(v interface{}) error {
return errors.New("response is nil")
}
defer c.Body.Close()

content, err := ioutil.ReadAll(c.Body)
if err != nil {
return errors.WithStack(err)
}

return jsoniter.Unmarshal(content, v)
return errors.WithStack(jsoniter.NewDecoder(c.Body).Decode(v))
}
2 changes: 1 addition & 1 deletion server/test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ func main() {
panic("test")
})

app.Run(":8080")
app.Run(":9000")
}

0 comments on commit 686790f

Please sign in to comment.