无法在if..else条件下获取变量数据:“ undefined err go”

I am trying to use HTTP Get with the use of if..else condition but I am getting an error:

undefined: err go

This is my code:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    num := 0
    if num == 0{
        resp, err := http.Get("https://httpbin.org/get")
    }else{
        resp, err := http.Get("https://google.com")
    }

    if err != nil {
        fmt.Println("error")
    }

    fmt.Println(resp.StatusCode)
}

I tried to defined the variables before the call:

var err error
var resp *http.Response

But then I received a different error:

err declared and not used

Any idea how I can solve it and why it happens ?
Because any way the resp and err should be received by the Get request.

Pre-declare both variables before the if and inside the if / else blocks use = instead of := to assign values to them.

Read more here:

Declarations and scope

Variable declarations

Short variable declarations