[部署日记]彻底解决初次安装Golang后vscode运行提示丢失包、更改安装位置后无法运行的问题

原标题:GO在Visual Studio Code初次运行时提示The "gopls" command is not available. Run "go get -v golang.org/x/tools/gopls" to install.

本以为VSC在商城装上插件后就能拎包入住,F5的时候我当场好家伙

 

 于是无脑Install...

Installing github.com/nsf/gocode FAILED
Installing github.com/uudashr/gopkgs/cmd/gopkgs FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/acroca/go-symbols FAILED
Installing github.com/rogpeppe/godef FAILED
Installing github.com/sqs/goreturns FAILED
Installing github.com/golang/lint/golint FAILED
Installing github.com/derekparker/delve/cmd/dlv FAILED
......

 好家伙,我当场在vscode里的terminal运行" go env ",其中显示

GOPROXY=https://proxy.golang.org,direct

然后在cmd里Ping了一下,好家伙

 

 

所以我们只需要更改好家伙的cn源就行了...

直接在vscode的Terminal(Ctrl+~)输入并回车

go env -w GOPROXY="https://goproxy.cn,direct" #GoProxy.cn镜像源
go env -w GOPROXY="https://proxy.golang.com.cn,direct" #GoProxy.io镜像源(20230429推荐,来自广东)
go env -w GO111MODULE="on" #可选,开了后就无需建立项目才可以运行

 

然后重启vscode,再点“Install all”

 

好家伙,搞定了

 

# gopls gotests gomodifytags impl goplay dlv staticcheck
go get -x github.com/cweill/gotests/gotests#@v1.6.0
go get -x github.com/fatih/gomodifytags#@v1.16.0
go get -x
github.com/josharian/impl#@v1.1.0 go get -x github.com/haya14busa/goplay/cmd/goplay#@v1.0.0 go get -x github.com/go-delve/delve/cmd/dlv@latest go get -x honnef.co/go/tools/cmd/staticcheck#@v0.2.2 go get -x golang.org/x/tools/gopls@latest

# 貌似可以不用指定版本了
go get -v golang.org/x/tools/gopls
go get -v github.com/cweill/gotests
go get -v github.com/fatih/gomodifytags
go get -v github.com/josharian/impl
go get -v github.com/uudashr/go-playground
go get -v github.com/uudashr/go-dlv
go get -v golang.org/x/tools/cmd/staticcheck


#20230429 好像输入下面这一串指令这样就可以了(实测1.22不行)
go mod tidy

 

 

帮到的话就点个好家伙的赞吧好家伙~

posted on 2021-06-25 14:43  Cela  阅读(4736)  评论(0编辑  收藏  举报

导航

Copyright ©Cela
Design by Cela