Skip to content

Commit

Permalink
Merge pull request #5 from DeBankDeFi/update_httplib
Browse files Browse the repository at this point in the history
httplib: add Put method for httplib
  • Loading branch information
barryz authored May 7, 2021
2 parents f1b2797 + 347d449 commit ed2f26b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions httplib/httplib.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ func (c *HTTPClient) Post(ctx context.Context, args *RequestArgs) error {
return c.doRequest(ctx, req, args)
}

// Put 发送 HTTP Put 请求
func (c *HTTPClient) Put(ctx context.Context, args *RequestArgs) error {
body, err := c.genBody(args)
if err != nil {
return syserror.Wrap(err, "generate http post body failed")
}
req, err := http.NewRequest("PUT", args.URL, body)
if err != nil {
return syserror.New(args.TraceID, "NEW_HTTP_REQUEST", err.Error(), map[string]interface{}{
"URL": args.URL,
})
}
return c.doRequest(ctx, req, args)
}

func (c *HTTPClient) doRequest(ctx context.Context, req *http.Request, args *RequestArgs) error {
c.setHeaders(req, args)
c.setParams(req, args)
Expand Down

0 comments on commit ed2f26b

Please sign in to comment.