英文:
Q: Getting Build Error "Invalid Import Path"
问题
我卡在使用"bee run"命令运行BeeGO应用程序上,它显示如下错误:
问题是我已经正确设置了我的GOPATH
为D:/Web Dev/GO/BeeGO/test-project/
,并且路由器路径确实存在,我还尝试手动构建文件,但它没有生成一个.exe文件。
有人知道如何解决这个问题吗?
我使用的是Windows 8.1 Pro(64位)。
谢谢!
英文:
I'm stuck on running the BeeGO app using "bee run" it says
The thing is I've already have setup properly my GOPATH
to D:/Web Dev/GO/BeeGO/test-project/
and also routers path does exist and I've tried to manual build the file but it doesn't generate an .exe file.
Anyone knows how to fix this?
I'm using Windows 8.1 Pro (64-bit)
Thanks
答案1
得分: 2
GO 期望在 $GOPATH 下按照以下方式组织目录结构,如 代码组织 中所述:
$GOPATH/src <--- 存放源代码的位置
/pkg
/bin
你不应该直接将源文件放在 $GOPATH (对于你的情况是 D:/Web Dev/GO/BeeGO/test-project/) 下,而是将代码移动到 $GOPATH/src
下。
D:/Web Dev/GO/BeeGO/test-project/src/main.go
D:/Web Dev/GO/BeeGO/test-project/src/quickstart/routers/routers.go
D:/Web Dev/GO/BeeGO/test-project/src/quickstart/controllers/controllers.go
导入路径应始终以 $GOPATH/src
开头。routers.go
可以使用 import "quickstart/routers"
导入,controllers.go
可以使用 import "quickstart/controllers"
导入。
英文:
GO expects the directory structure under $GOPATH in following ways as described in code organization:
$GOPATH/src <--- where your source code goes
/pkg
/bin
Instead of placing your source files directly under $GOPATH (D:/Web Dev/GO/BeeGO/test-project/ for your case), you want to move your code under $GOPATH/src
.
D:/Web Dev/GO/BeeGO/test-project/src/main.go
D:/Web Dev/GO/BeeGO/test-project/src/quickstart/routers/routers.go
D:/Web Dev/GO/BeeGO/test-project/src/quickstart/controllers/controllers.go
import path should be always starting from $GOPATH/src
. routers.go
can be always imported as import "quickstart/routers"
and controllers.go
can be imported as import "quickstart/controllers"
.
答案2
得分: 0
这不是导入包的正确方式。
导入路径是相对于$GOPATH/src
的。请使用以下方式导入:
import "quickstart/routers"
英文:
That's not how you import a package.
The import path is relative to $GOPATH/src
. use:
import "quickstart/routers"
答案3
得分: 0
最终修复了框架中的错误,
我所做的:
在 main.go
中从 "D:/Web Dev/GO/BeeGO/test-project/quickstart/routers"
导入,
我将其更改为 _"../quickstart/routers"
,确保包含 _
,这意味着即使不使用该库也要导入它,
然后在 routers/router.go
中,我将导入路径从 "D:/Web Dev/GO/BeeGO/test-project/quickstart/controllers"
更改为 "../controllers"
。
似乎 BeeGO 没有正确生成模板,导致构建失败。
英文:
Finally fixed the bug from the framework,
What I did:
in main.go
import from
"D:/Web Dev/GO/BeeGO/test-project/quickstart/routers"
I changed it to _"../quickstart/routers"
make sure to include _
this means to import the library even if it is not used,
Then in the routers/router.go
I changed the import path
"D:/Web Dev/GO/BeeGO/test-project/quickstart/controllers"
to "../controllers"
It seems BeeGO doesn't generate the template properly and caused the build to fail.
答案4
得分: 0
这个错误的另一个可能性是当你从互联网上复制粘贴代码时,导入语句中的
import "quickstart/routers"
变成了
import "quickstart/routers "
这是因为一些 CMS/Blog 系统中的错误导致的(请注意引号闭合之前的末尾空格)。
英文:
Another possiblity for this error, is when you copy-paste code from the internet,
and
import "quickstart/routers"
became
import "quickstart/routers "
due to bugs in some CMS/Blog systems (notice the space at the end before the closing quote...).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论