go 新建package其它包無法直接調用,是不是要go install 一下?
2 回答

MMTTMM
TA貢獻1869條經驗 獲得超4個贊
If the name of a package does not start with . or /, like “fmt” or “container/list”, Go looks for it inthe global Go tree. If it starts with ./ the package is searched in the actual directory; starting with /(even on Windows) it is searched for in the (absolute) path indicated.
出自 The Way To Go
按照我自己理解解釋下:
$GOROOT 系統中Go的根目錄
$GOPATH 用來安裝第三方包的目錄,自己隨便指定
例如,使用 go get xxx 安裝的包會被放到 $GOPATH/src 下面
對于自己寫的模塊,最簡單的方式就是用相對或絕對路徑導入
如果想方便地在全局使用,像 "import "fmt"
一樣
推薦在$GOPATH/src下建立相應的package,當然放$GOROOT也是可以的
- 2 回答
- 0 關注
- 1843 瀏覽
添加回答
舉報
0/150
提交
取消