package main
import (
"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)
运行go mod init MODULE_NAME
(如果项目在GOROOT或GOPATH外部)或只是简单地go mod init
(如果项目在GOROOT或GOPATH内部)。该命令应在项目的根文件夹上运行。这将创建一个go.mod
文件,该文件将使您能够解析您的软件包。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句