Error handling is not possible when I write a method that returns an error with defer in one-liner. It will be warned by IDE linter etc.
I write the following code to avoid it.
package main
import (
"io/ioutil"
"log"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://example.com", nil)
cli := &http.Client{}
res, _ := cli.Do(req)
defer func() {
_ = res.Body.Close() // catch the error
}()
b, _ := ioutil.ReadAll(res.Body)
log.Println(string(b))
}