如何防范声明的变量和发现的错误

I have a small issue which I know why it's there but can't find the solution to it.

What happens is I have a variable that won't be used if error occurred and this causes a compiler error.

Code:

func findAll(query string) ([]Result, error) {
    var res *http.Response
    var err error

    if res, err := http.Get("url" + url.QueryEscape(query)); err != nil {
        return []Result{}, err
    }

    defer res.Body.Close()
    var body []byte
    if body, err := ioutil.ReadAll(res.Body); err != nil {
        return [] Result{}, err
    }

    var f FilteredSearch
    err = xml.Unmarshal(body, &f)
    return f.Results, err
}

First issue is in this line :

if res, err := http.Get("url" + url.QueryEscape(query)); err != nil

res declared and not used

Same issue here:

if body, err := ioutil.ReadAll(res.Body); err != nil 

body declared and not used

You have already declared the two variables on top of your file and, when you use :=, you are re-declaring them. The solution is to use = instead:

if res, err = http.Get("url" + url.QueryEscape(query)); err != nil {