为了账号安全,请及时绑定邮箱和手机立即绑定

Golang 错误:未定义:http.NewSingleHostReverseProxy

Golang 错误:未定义:http.NewSingleHostReverseProxy

Go
catspeake 2021-07-01 10:00:42
我尝试使用 Golang 构建一个简单的程序,这里是:package mainimport (        "net/http"        "net/http/httputil"        "log")func main(){        proxy := http.NewSingleHostReverseProxy( &http.URL{Scheme:"http",Host:"www.google.com",Path:"/"})        err := http.ListenAndServe(":8080", proxy)        if err != nil {                log.Fatal("ListenAndServe: ", err.String())        }}建造:go build myprogram.go输出:command-line-arguments./myprogram.go:5: imported and not used: "net/http/httputil"./myprogram.go:11: undefined: http.NewSingleHostReverseProxy./myprogram.go:11: undefined: http.URL./myprogram.go:15: err.String undefined (type error has no field or method String)我注意到 http.NewSingleHostReverseProxy 在“net/http/httputil”包中,为什么我会看到这样的错误?也许我需要一个特定的命令来正确构建它?编辑 后记,这是新的工作代码:package mainimport (        "net/http"        "net/http/httputil"        "net/url"        "log")func main(){        proxy := httputil.NewSingleHostReverseProxy( &url.URL{Scheme:"http",Host:"www.google.com",Path:"/"})        err := http.ListenAndServe(":8080", proxy)        if err != nil {                log.Fatal("ListenAndServe: ", err)        }}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 295 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信