0
点赞
收藏
分享

微信扫一扫

初学GO遇到的问题

GG_lyf 2022-02-27 阅读 72

新手用VSCode写GO会遇到的问题
1.VScode安装go插件报错。
这个问题据笔者查询发现是个bug,科学上网也无法下载,安装插件会报错如下:

Installing github.com/cweill/gotests/... FAILED
Installing github.com/derekparker/delve/cmd/dlv SUCCEEDED
8 tools failed to install.
go-outline:
Error: Command failed: D:\Go\bin\go.exe get -u -v github.com/ramya-rao-a/go-outline
github.com/ramya-rao-a/go-outline (download)
Fetching https://golang.org/x/tools/go/buildutil?go-get=1
https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

解决如下:
以windows为例,
在cmd 窗口中执行下列语句

go env -w GO111MODULE=on

go env -w GOPROXY=https://goproxy.io,direct

这里https://goproxy.io是一个国内的代理,输入完成后关闭vscode重新打开,再次点击install all安装即可!

若还是失败可以手动安装:

go get -u -v github.com/mdempsky/gocode
go get -u -v github.com/uudashr/gopkgs/v2/cmd/gopkgs
go get -u -v github.com/ramya-rao-a/go-outline
go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct
go get -u -v github.com/haya14busa/goplay/cmd/goplay
go get -u -v github.com/godoctor/godoctor
go get -u -v github.com/go-delve/delve/cmd/dlv
go get -u -v github.com/stamblerre/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v golang.org/x/lint/golint
.........

2.运行hello world

package main
import "fmt"
func main() {
	fmt.Println("hello world!")
}

出现以下错误:

go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Build process exiting with code: 1 signal: null

解决如下,以windows为例子:
在cmd中输入:

go env -w GO111MODULE=auto

因为go命令现在默认以模块感知模式构建包,即使在没有go.mod的情况下也是如此。所以可以设置GO111MODULE为自动启用模块感知模式,只有当go.Mod文件存在于当前目录或任何父目录中。

举报

相关推荐

0 条评论