package mainimport ( "fmt" "controller/userhandler" //not able to import this custom package "github.com/gin-gonic/gin" "net/http" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/postgres")func main(){}下面的代碼顯示 Go 只在 GOROOT 中搜索包。controller/userhandler在GOROOT中找不到之后,理想情況下,它應該在GOPATH中查找包,但它沒有。我已經將GOPATH設置為我的工作區路徑,其中包括以下文件夾:bin、src和pkg.$ go build main.go main.go:5:2: package controller/userhandler is not in GOROOT (/usr/local/go/src/controller/userhandler)
1 回答

蕪湖不蕪
TA貢獻1796條經驗 獲得超7個贊
運行go mod init MODULE_NAME
(如果項目在GOROOT或GOPATH之外)或只是簡單地go mod init
(如果項目在GOROOT 或 GOPATH內)。該命令應在項目的根文件夾中運行。這將創建一個go.mod
文件,使go能夠解析您的包。
- 1 回答
- 0 關注
- 188 瀏覽
添加回答
舉報
0/150
提交
取消