【发布时间】:2016-04-04 12:50:29
【问题描述】:
我知道互联网上到处都是类似的问题,我尝试了所有建议的解决方案,但至少 2 天无法弄清楚。
我尝试使用 IntelliJ IDEA 部署小型 Go 服务器,它运行良好,它可以构建/运行我的代码,但如果我使用终端作为示例:
go build ./...
我看到类似的东西:
OS-X-Dennis:backend denis$ go build ./...
out/production/mypocket_backend/server.go:4:2: cannot find package "api.jwt.auth/routers" in any of:
/usr/local/go/src/api.jwt.auth/routers (from $GOROOT)
/Users/denis/Programming/Golang/src/api.jwt.auth/routers (from $GOPATH)
OS X 10.11.2、IntelliJ IDEA 2016.1
$GOPATH = "用户/denis/Programming/Golang"
$GOROOT = "/usr/local/go"
$PATH = "$PATH:$GOPATH/bin"
这些路径正确吗?
这是我的工作结构:
/Golang/
.bin/
.pkg/
.darwin-amd64/
.//other folders/
.src/
.github.com/
.backend/ //project's source
/src
/api.jwt.auth/
//source code
.server.go - file with main func
//other files as example .gitignore
.//other folders//
我看到日志显示了我的项目的错误路径。
now
/Users/denis/Programming/Golang/src/api.jwt.auth/routers
should
/Users/denis/Programming/Golang/src/backend/src/api.jwt.auth/routers
我不知道我应该在哪里更正这条路径。
【问题讨论】:
-
后端文件夹是您项目的来源还是那是什么?项目中包含的所有包都需要位于 GOPATH 的 src 文件夹中。我敢打赌,您的本地文件夹结构与服务器上的不同
-
如何导入
api.jwt.auth包?我有一种强烈的感觉,你没有正确导入。 -
应该是
import "backend/src/api.jwt.auth",而不是api.jwt.auth。 -
@nevets,我编辑了我的问题,我也编辑了我的导入,但没有帮助
-
@tier1,是的,它是一个源项目目录,所有需要项目的依赖项都包含在 GOPATH/src 中。
标签: intellij-idea go