http.NoBody should be preferred to the nil request body
169
170// Request sends http json request.
171func Request(ctx context.Context, method, url string, payload, data interface{}) error {
172 req, err := http.NewRequestWithContext(ctx, method, url, nil)173 if err != nil {
174 return err
175 }
Description
http.NoBody
is an io.ReadCloser
with no bytes. Read always returns EOF
and
Close
always returns nil
.
Bad practice
func foo(url string) {
http.NewRequest("GET", url, nil)
}
Recommended
func foo(url string) {
http.NewRequest("GET", url, http.NoBody)
}