没有不值得去解决的问题,也没有不值得去学习的技术!

运行 Go 报错:exercise-maps.go:4:2: cannot find package “code.google.com/p/go-tour/wc” in any of: c:\go\src\code.google.com\p\go-tour\wc (from $GOROOT) 的解决

运行文件,Go 报错:exercise-maps.go:4:2: cannot find package "code.google.com/p/go-tour/wc" in any of: c:\go\src\code.google.com\p\go-tour\wc (from $GOROOT) C:\Users\Administrator\go\src\code.google.com\p\go-tour\wc (from $GOPATH)

1、查看 Go 文件:exercise-maps.go,代码如下


package main

import (
	"code.google.com/p/go-tour/wc"
)

func WordCount(s string) map[string]int {
	return map[string]int{"x": 1}
}

func main() {
	wc.Test(WordCount)
}


2、运行文件,Go 报错:exercise-maps.go:4:2: cannot find package “code.google.com/p/go-tour/wc” in any of:
c:\go\src\code.google.com\p\go-tour\wc (from $GOROOT)
C:\Users\Administrator\go\src\code.google.com\p\go-tour\wc (from $GOPATH),如图1

运行文件,Go 报错:exercise-maps.go:4:2: cannot find package "code.google.com/p/go-tour/wc" in any of:         c:\go\src\code.google.com\p\go-tour\wc (from $GOROOT)         C:\Users\Administrator\go\src\code.google.com\p\go-tour\wc (from $GOPATH)
图1

PS E:\wwwroot\go\moretypes> go run exercise-maps.go
exercise-maps.go:4:2: cannot find package "code.google.com/p/go-tour/wc" in any of:
        c:\go\src\code.google.com\p\go-tour\wc (from $GOROOT)
        C:\Users\Administrator\go\src\code.google.com\p\go-tour\wc (from $GOPATH)


3、打开 Go Tour 在 GitHub 上的网址:https://github.com/golang/tour ,开启蓝灯连接后,基于源代码安装 Go Tour,报错:unrecognized import path “golang.org/x/tour”,Ping golang.org,提示请求超时,如图2

打开 Go Tour 在 GitHub 上的网址:https://github.com/golang/tour ,开启蓝灯连接后,基于源代码安装 Go Tour,报错:unrecognized import path "golang.org/x/tour",Ping golang.org,提示请求超时
图2

PS E:\wwwroot\go\moretypes> go get golang.org/x/tour
package golang.org/x/tour: unrecognized import path "golang.org/x/tour" (https fetch: Get https://golang.org/x/tour?go-g
et=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly res
pond after a period of time, or established connection failed because connected host has failed to respond.)


4、在 Chrome 中打开网址:https://golang.org/ ,可以正常打开,如图3

在 Chrome 中打开网址:https://golang.org/ ,可以正常打开
图3

5、利用蓝灯为命令行配置 HTTP 代理,查看蓝灯的高级设置 – HTTP(S)代理服务器,如图4

利用蓝灯为命令行配置 HTTP 代理,查看蓝灯的高级设置 - HTTP(S)代理服务器
图4

6、在 cmd 中设置两个环境变量 HTTP_PROXY 和 HTTPS_PROXY ,执行以下两个命令设置环境变量,完成配置,基于源代码安装 Go Tour,未报错,虽然仍然无法 Ping 通,但是可以通过 Curl 打开 www.google.com,表示 HTTP 代理已经设置成功,如图5

在 cmd 中设置两个环境变量 HTTP_PROXY 和 HTTPS_PROXY ,执行以下两个命令设置环境变量,完成配置,基于源代码安装 Go Tour,未报错,虽然仍然无法 Ping 通,但是可以通过 Curl 打开 www.google.com,表示 HTTP 代理已经设置成功
图5

C:\Users\Administrator>set HTTP_PROXY=http://127.0.0.1:50999

C:\Users\Administrator>set HTTPS_PROXY=http://127.0.0.1:50999

C:\Users\Administrator>go get golang.org/x/tour

C:\Users\Administrator>ping golang.org

正在 Ping golang.org [216.239.37.1] 具有 32 字节的数据:
请求超时。
请求超时。
请求超时。
请求超时。

216.239.37.1 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失),

C:\Users\Administrator>curl -vv http://www.google.com
* Rebuilt URL to: http://www.google.com/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 50999 (#0)
> GET http://www.google.com/ HTTP/1.1
> Host: www.google.com
> User-Agent: curl/7.55.1
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 301 Moved Permanently
< Connection: close
< Cache-Control: max-age:86400
< Date: Friday, 27-Dec-19 16:57:05 CST
< Expires: Sat, 28 Dec 2019 16:57:05 GMT
< Keep-Alive: timeout=58
< Location: https://www.google.com/
< Content-Length: 0
<
* Closing connection 0



7、查看目录:C:\Users\Administrator\go\src\golang.org\x,目录:tour 已经存在,如图6

查看目录:C:\Users\Administrator\go\src\golang.org\x,目录:tour 已经存在
图6

8、编辑 Go 文件:exercise-maps.go,将 code.google.com/p/go-tour 替换为:golang.org/x/tour,代码如下


package main

import (
	"golang.org/x/tour/wc"
)

func WordCount(s string) map[string]int {
	return map[string]int{"x": 1}
}

func main() {
	wc.Test(WordCount)
}


9、运行文件,正常运行,如图7

运行文件,正常运行
图7

PS E:\wwwroot\go\moretypes> go run exercise-maps.go
FAIL
 f("I am learning Go!") =
  map[string]int{"x":1}
 want:
  map[string]int{"Go!":1, "I":1, "am":1, "learning":1}


需要长期技术维护或远程问题排查?

我是拥有 15+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。

如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:

  • ✅ PHP / Laravel / Yii2 老项目无人维护
  • ✅ Go / Gin 后端接口需要排查或优化
  • ✅ WordPress 网站访问慢、报错或插件冲突
  • ✅ Nginx / MySQL / Redis / Linux 服务器异常
  • ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
  • ✅ 需要长期远程技术支持或兼职维护

更多介绍请查看:关于我 & 合作

微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理