Go get使用代理

在vscode中使用golang時,經(jīng)常會出現(xiàn)安裝第三方工具的時候失敗的問題,一般來說都是下載了golang.org/x/...下面的包或者要下載的工具依賴于golang.org/x/...的包所導致的,在國內(nèi)是不會很順利的下載和安裝的。

Installing github.com/mdempsky/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 golang.org/x/tools/cmd/guru FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing github.com/go-delve/delve/cmd/dlv FAILED
Installing github.com/rogpeppe/godef FAILED
Installing golang.org/x/tools/cmd/goimports FAILED
Installing golang.org/x/lint/golint FAILED

go get默認使用git來作為版本管理工具,如果對git設(shè)置了代理能否下載成功呢?

git config --global http.proxy 'http://127.0.0.1:8123'
git config --global https.proxy 'http://127.0.0.1:8123'

很遺憾,即使你對git設(shè)置了代理,也無法成功的下載安裝golang.org下的包,假如你要安裝golang.org/x/tools/cmd/guru這個包,當你使用go get去下載安裝包時,首先會訪問https://golang.org/x/tools/cmd/guru?go-get=1這個url來獲取版本庫的類型,是git還是svn或者其他的版本管理工具,這個http請求是git之外的,所以這有對這個http請求設(shè)置了代理,然后對git設(shè)置代理,才能成功的下載安裝該庫。

# 在終端中執(zhí)行
export https_proxy=http://127.0.0.1:8123
export http_proxy=http://127.0.0.1:8123
git config --global http.proxy 'http://127.0.0.1:8123'
git config --global https.proxy 'http://127.0.0.1:8123'

前提是你擁有一個http或者socks代理,如果沒有的話,還是老老實實的在github.com/golang/...上下載對應(yīng)的包然后進行替換吧。

設(shè)置了代理之后,再次執(zhí)行g(shù)o get命令:


go get -v github.com/acroca/go-symbols

golang.org/x/tools/go/buildutil
# golang.org/x/tools/go/buildutil
Workbench/golang/src/golang.org/x/tools/go/buildutil/buildutil_go16.go:14:38: undefined: build.AllowVendor

這次又出錯了,原因應(yīng)該是golang.org/x/tools/go/buildutil包太老了,直接更新相關(guān)的依賴包即可:

go get -v -u github.com/acroca/go-symbols

github.com/acroca/go-symbols (download)
Fetching https://golang.org/x/tools/go/buildutil?go-get=1
Parsing meta tags from https://golang.org/x/tools/go/buildutil?go-get=1 (status code 200)
get "golang.org/x/tools/go/buildutil": found meta tag get.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/go/buildutil?go-get=1
get "golang.org/x/tools/go/buildutil": verifying non-authoritative meta tag
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
package golang.org/x/tools/go/buildutil: golang.org/x/tools is a custom import path for https://go.googlesource.com/tools, but /home/lu/Workbench/golang/src/golang.org/x/tools is checked out from https://github.com/golang/tools

這次就成功更新并安裝了,重啟vscode,各項功能也正常了。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容