1、去我的電腦添加用戶變量 GOPROXY 為 https://goproxy.cn 如果這個代理無效可以使用阿里雲的 https://mirrors.aliyun.com/goproxy/
2、搜索go擴展后安裝
3、安裝go擴展依賴的擴展 - command+shift+P 輸入 然后鍵入:go:install/update tools
,將所有 的插件都勾選上,然后點擊 OK 即開始安裝
4、增加vscode設置
"go.useLanguageServer": true,
備注:
如果安裝失敗,網上說的自行去對應插件地址 比如需要安裝 lint 就git clone https://github.com/golang/lint 然后 go build 將編譯好的程序放在目錄go path上,實在過於麻煩
這里又非常容易安裝失敗,由於github非常非常緩慢,所以設置一下代理
set GOPROXY=https://goproxy.io;
可以在全局執行或者當前文件夾終端執行
https://goframe.org/prepare/gomodule
以上地址可以獲取aliyun或其他的代理地址
等所有都輸出
Installing github.com/mdempsky/gocode SUCCEEDED Installing github.com/uudashr/gopkgs/cmd/gopkgs SUCCEEDED Installing github.com/ramya-rao-a/go-outline SUCCEEDED Installing github.com/acroca/go-symbols SUCCEEDED Installing golang.org/x/tools/cmd/guru SUCCEEDED Installing golang.org/x/tools/cmd/gorename SUCCEEDED Installing github.com/cweill/gotests/... SUCCEEDED Installing github.com/fatih/gomodifytags SUCCEEDED Installing github.com/josharian/impl SUCCEEDED Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED Installing github.com/godoctor/godoctor SUCCEEDED Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED Installing github.com/stamblerre/gocode SUCCEEDED Installing github.com/rogpeppe/godef SUCCEEDED Installing golang.org/x/tools/cmd/goimports SUCCEEDED Installing golang.org/x/lint/golint SUCCEEDED All tools successfully installed. You are ready to Go :).
表示安裝擴展依賴完成
以下配置可能會用上
在vscode的設置頁面,點擊右上角的以json格式配置
新增以下json配置
"go.useLanguageServer": true, "go.goroot": "C:\\Go", "go.formatTool": "goimports",
"[go]": {"editor.formatOnSave": false},
"editor.links": false // 點擊引用不打開外部網站
還需要其他配置比如,保存以后不自動格式化等請查閱
https://github.com/Microsoft/vscode-go
或者
https://code.visualstudio.com/
https://github.com/microsoft/vscode-go/wiki/Go-modules-support-in-Visual-Studio-Code
4. 最好將項目放在go默認的個人代碼倉庫比如
C:\Users\user\go
文件夾下面的src路徑