gometalinter / errcheck returns a warning on deferring a func which returns a variable
问题 gometalinter and errcheck return me a warning about deferring a function which returns a variable. Example in a web request: defer r.Body.Close() In this case, Close returns an error variable and it's not checked. Is the best method / idiomatic to defer it inside another function? defer func() { err := r.Body.Close() if err != nil { // fmt, panic or whatever } }() 回答1: If a deferred function has any return values, they are discarded when the function completes (for more details check Spec: