Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在导入包时在GOPATH中搜索包? 主程序包 进口( “fmt” “controller/userhandler”//无法导入此自定义包 “github.com/gin gonic/gin” “net/http” “github.com/jinju/gorm” _“github.com/jinzhu/gorm/diagnols/postgres” ) func main(){ }_Go_Import_Gopath - Fatal编程技术网

如何在导入包时在GOPATH中搜索包? 主程序包 进口( “fmt” “controller/userhandler”//无法导入此自定义包 “github.com/gin gonic/gin” “net/http” “github.com/jinju/gorm” _“github.com/jinzhu/gorm/diagnols/postgres” ) func main(){ }

如何在导入包时在GOPATH中搜索包? 主程序包 进口( “fmt” “controller/userhandler”//无法导入此自定义包 “github.com/gin gonic/gin” “net/http” “github.com/jinju/gorm” _“github.com/jinzhu/gorm/diagnols/postgres” ) func main(){ },go,import,gopath,Go,Import,Gopath,下面的代码显示Go只在GOROOT中搜索包。在GOROOT中找不到controller/userhandler后,理想情况下,它应该在GOPATH中查找包,但它没有 我已经为我的工作区路径设置了GOPATH,其中包括文件夹:bin、src和pkg $go build main.go main.go:5:2:包控制器/userhandler不在GOROOT(/usr/local/go/src/controller/userhandler)中 运行go mod init MODULE\u NAME(

下面的代码显示Go只在GOROOT中搜索包。在GOROOT中找不到
controller/userhandler
后,理想情况下,它应该在GOPATH中查找包,但它没有

我已经为我的工作区路径设置了GOPATH,其中包括文件夹:
bin
src
pkg

$go build main.go
main.go:5:2:包控制器/userhandler不在GOROOT(/usr/local/go/src/controller/userhandler)中

运行
go mod init MODULE\u NAME
(如果项目在GOROOTGOPATH之外),或者只运行
go mod init
(如果项目在GOROOT或GOPATH内部)。该命令应在项目的根文件夹上运行。这将创建一个
go.mod
文件,该文件将启用go解析您的软件包。

能否显示您的代码?默认情况下,go使用模块(请参阅和)。如果没有答案,我们无法确切地知道你在做什么。这回答了你的问题吗?