創(chuàng)建項(xiàng)目
Location:新項(xiàng)目文件夾GOROOT:go 安裝根目錄Proxy:https://goproxy.io,direct
重要:https://goproxy.io是下載go包的代理地址,設(shè)置后可在國內(nèi)正常下載go倉庫/github的包。
創(chuàng)建一個(gè)go文件
創(chuàng)建了一個(gè)test.go
下載安裝需要的包
這里演示安裝mysql driver包:github.com/go-sql-driver/mysql
直接import顯示找不到包,使用左下方命令行工具,安裝mysql driver
使用go get 命令安裝包
使用go get github.com/go-sql-driver/mysql安裝mysql driver,安裝成功后test.go中import的包變綠。
我已經(jīng)安裝過一次,第一次安裝應(yīng)該會(huì)在命令窗口出現(xiàn)一些信息。
補(bǔ)充:Goland 使用 go modules的TIPS
運(yùn)行g(shù)o mod tidy,報(bào)錯(cuò):
go: golang.org/x/[email protected]: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: c
onnectex: 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.)
go: error loading module requirements
原因是某些依賴在國內(nèi)被墻了,這邊可以設(shè)置一下proxy,就可以解決:
進(jìn)入Goland的設(shè)置界面,F(xiàn)ile/Settings/Go/Go Module(vgo),設(shè)置一下Proxy為:https://goproxy.io。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
原文鏈接:https://blog.csdn.net/qq_33398607/article/details/106099939