如何在Go中使用http包时检索最终URL目标?

如何在Go中使用http包时检索最终URL目标?,go,Go,大多数站点在请求期间重定向到另一个URL。例如:http://example.com 可能可能重定向到http://mobile.example.com 有没有办法找回最终目的地?例如,对于cURL,他们称之为有效URL package main import ( "fmt" "net/http" ) func main() { getURL := "http://pkgdoc.org/" fmt.Println("getURL:", getURL)

大多数站点在请求期间重定向到另一个URL。例如:
http://example.com 可能
可能重定向到
http://mobile.example.com

有没有办法找回最终目的地?例如,对于
cURL
,他们称之为
有效URL

package main

import (
    "fmt"
    "net/http"
)

func main() {
    getURL := "http://pkgdoc.org/"
    fmt.Println("getURL:", getURL)
    resp, err := http.Get(getURL)
    if err != nil {
        fmt.Println(err)
        return
    }
    finalURL := resp.Request.URL.String()
    fmt.Println("finalURL:", finalURL)
}
输出:

getURL: http://pkgdoc.org/
finalURL: http://godoc.org/

我无法获得“.”的最终url。因为google.com本身就是一个仍在获得swiggy.com帮助的网站?