[go-nuts] Re: if i catch resp.StatusCode != http.StatusOK and return early from my function, do i still have to close resp.Body??

2018-01-28 Thread K Wang
I would do put it right after resp, err := client.Do(req) if err!=nil{ // wrap a an err return return errWrap(err) } defer resp.Body.Close() log.Printf("resp: %+v\n", resp) if resp.StatusCode != http.StatusOK { } Some linter may also suggest you catch the body.Close() err as well

[go-nuts] Re: Is there a best way to use a global httpclient but with a different timeout setting per request?

2017-11-02 Thread K Wang
ctx, cancel = context.WithTimeout(context.Background(), client.Timeout) On Tuesday, October 31, 2017 at 5:52:29 AM UTC-7, 慕希颜 wrote: > > Is there a way to add a timeout setting for per request if i declare a > global var? Because in my case i need different timeout setting for per > request.