...
Installing golang.org/x/tools/gopls@latest FAILED
{
"killed": false,
"code": 1,
"signal": null,
"cmd": "D:\\Program Files\\Go\\bin\\go.exe install -v golang.org/x/tools/gopls@latest",
"stdout": "",
"stderr": "go install: golang.org/x/tools/gopls@latest: module golang.org/x/tools/gopls: Get \"https:///goproxy.cn/golang.org/x/tools/gopls/@v/list\": http: no Host in request URL\n"
}
...
大多数人是github上不去,但是我这可以上去,这里报的是no Host。
查询了很多发现大多是配代理,然后去github下载,然后再执行。我这是下载以后执行仍然报错。
这里记录下解决方法。
或者打开Powershell,输入:
$env:GO111MODULE="on"
$env:GOPROXY="https://goproxy.io"
go env -w GOPROXY=https://goproxy.cn,direct
//go env -w GOPROXY=https://goproxy.io,direct
go env -w GOPRIVATE=*.corp.example.com
goproxy.io和goproxy.cn都可以
在终端中执行下面的命令会输出go.evn配置
go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=D:\Program Files\Go\bin
set GOCACHE=C:\Users\admin\AppData\Local\go-build
set GOENV=C:\Users\admin\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\server\GO\pkg\mod
set GONOPROXY=*.corp.example.com
set GONOSUMDB=*.corp.example.com
set GOOS=windows
set GOPATH=D:\server\GO
set GOPRIVATE=*.corp.example.com
set GOPROXY=https://goproxy.io
set GOROOT=D:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.5
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\admin\AppData\Local\Temp\go-build957788953=/tmp/go-build -gno-record-gcc-switches
注意GOPATH是go的依赖包目录,GOROOT是GO的安装目录
如果是在vsCode终端里执行的要关闭终端后再输出才会看到更新,只重启VsCode终端这里显示的配置是不会变的!
然后在VSCode里ctrl+shift+P调出搜索项,输入go install 选择 Go:Install/Update Tools 然后全选执行即可
这里我看很多人执行成功了,但是我这行不通。
在%GOPATH%目录下创建文件夹:
src/golang.org/x/
打开终端,切换到%GOPATH%/src/golang.org/x/目录下,执行clone:
cd $env:GOPATH/src/golang.org/x/
git clone https://github.com/golang/tools.git
git clone https://github.com/golang/lint.git
我的%GOPATH%目录是D:\server\GO, 这时的当前目录是这样的:
然后在终端中切换到%GOPATH%\src\golang.org\x\下,执行之安装之前安装失败的插件,比如:
go install -v golang.org/x/tools/gopls
但是我这里仍然失败了,提示:
PS D:\server\GO\src> go install -v golang.org/x/tools/gopls
go install: version is required when current directory is not in a module
Try 'go install golang.org/x/tools/gopls@latest' to install the latest version
后添加@latest版本安装成功:
PS D:\server\GO\src> go install -v golang.org/x/tools/gopls@latest
...
PS D:\server\GO\src> go install -v github.com/haya14busa/goplay/cmd/goplay@latest
...
PS D:\server\GO\src> go install -v github.com/go-delve/delve/cmd/dlv@latest
...
PS D:\server\GO\src> go install -v github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest
PS D:\server\GO\src> go install -v github.com/cweill/gotests/gotests@latest
PS D:\server\GO\src> go install -v github.com/fatih/gomodifytags@latest
PS D:\server\GO\src> go install -v github.com/josharian/impl@latest
PS D:\server\GO\src> go install -v github.com/haya14busa/goplay/cmd/goplay@latest
这里前面是使用的目录,后面是github.com,因为我本地报错是vs自动安装的时候两个地址都报了,所以我是两个都尝试安装了。
以上。