获取构建错误“无效的导入路径”。

huangapple go评论96阅读模式
英文:

Q: Getting Build Error "Invalid Import Path"

问题

我卡在使用"bee run"命令运行BeeGO应用程序上,它显示如下错误:

获取构建错误“无效的导入路径”。

问题是我已经正确设置了我的GOPATHD:/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  &lt;--- 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 &quot;quickstart/routers&quot; and controllers.go can be imported as import &quot;quickstart/controllers&quot;.

答案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 &quot;quickstart/routers&quot;

答案3

得分: 0

最终修复了框架中的错误,

我所做的:

main.go 中从 &quot;D:/Web Dev/GO/BeeGO/test-project/quickstart/routers&quot; 导入,

我将其更改为 _&quot;../quickstart/routers&quot;,确保包含 _,这意味着即使不使用该库也要导入它,

然后在 routers/router.go 中,我将导入路径从 &quot;D:/Web Dev/GO/BeeGO/test-project/quickstart/controllers&quot; 更改为 &quot;../controllers&quot;

似乎 BeeGO 没有正确生成模板,导致构建失败。

英文:

Finally fixed the bug from the framework,

What I did:

in main.go import from
&quot;D:/Web Dev/GO/BeeGO/test-project/quickstart/routers&quot;

I changed it to _&quot;../quickstart/routers&quot; 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
&quot;D:/Web Dev/GO/BeeGO/test-project/quickstart/controllers&quot; to &quot;../controllers&quot;

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 &quot;quickstart/routers&quot;

became

import &quot;quickstart/routers &quot;

due to bugs in some CMS/Blog systems (notice the space at the end before the closing quote...).

huangapple
  • 本文由 发表于 2014年12月13日 07:35:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/27453769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定