Golang那些坑

vsc中报错Failed to find the "go" binary from PATH

在vsc setting json文件中加入一段配置即可

"go.goroot": "<GO的sdk路径>"

原文链接

package xxx is not in GOROOT (/usr/lib/go/src/xxx)

先说解决方案:
在指令前加上GO111MODULE=off,示例:GO111MODULE=off go run hello.go

大致原因是,从 Go1.11 开始, Go 官方加入 Go Module 支持, Go1.12 成为默认支持。当GO111MODULE=on时,$GOPATH/src将不再用于解析包的导入,也就是go tool不会从 GOPATH 中寻找应的包,而是会到$GOROOT/src中去寻找包,$GOPATH仅作为下载源代码($GOPATH/pkg/mod)和可执行命令($GOPATH/bin)的存储地址

When using modules, GOPATH is no longer used for resolving imports.
However, it is still used to store downloaded source code (in GOPATH/pkg/mod)
and compiled commands (in GOPATH/bin). --$ go help gopath | grep -B 1 -A 4 "GOPATH and Modules"

原文链接

posted @ 2022-11-23 15:52  Tank-Li  阅读(202)  评论(0编辑  收藏  举报