英文:
Revel and golang import too physical?
问题
刚开始使用Go/Revel。我将"examples/booking"应用程序复制到"examples/booking2"目录中,这样我就可以在不影响原始应用程序的情况下进行修改。
当我运行它时,得到了奇怪的结果,特别是数据库中的初始数据似乎被复制了。
我追踪到了问题的根源:
import "github.com/revel/examples/booking/app/models"
一旦我将所有相关的导入中的"booking"改为"booking2",一切都正常了。但我首先想到的是"为什么导入路径是这么物理的?"。我在想,在应用程序内部是否有一种相对引用应用程序各个包的方式,而不必引用应用程序所在的物理路径。
有没有办法做到这一点?
我甚至不确定这是"Go"的事情,还是"Revel"的事情。
谢谢。
英文:
just starting with go/revel. I copied the "examples/booking" app into "examples/booking2" directory so i could muck with it w/o impacting the original.
When I ran it I got weird results, in particular the initial data in the db seemed to be duplicated.
I tracked this down to the imports:
import "github.com/revel/examples/booking/app/models"
Once I changed "booking" to "booking2" in all the relevant imports things were fine. But my first thought is "why is an import path so physical?". I'm thinking that within the application there should be a way to relatively reference the app's various packages w/o having to reference the physical path where the app resides.
Is there a way to do that?
Not even sure if this is "go" thing, or a "revel" thing.
Thx.
答案1
得分: 1
导入路径直接映射到文件系统路径,相对于$GOPATH/src/
。
https://golang.org/doc/code.html#ImportPaths
看起来你可以这样进行相对导入:
../other-pkg
但这不是惯用的或推荐的方法(https://stackoverflow.com/questions/10687627/relative-import-from-parent-directory)。
英文:
The import path maps directly to the filesystem path, relative to $GOPATH/src/
.
https://golang.org/doc/code.html#ImportPaths
It seems that you can do a relative import like this:
../other-pkg
But it's not idiomatic or recommended.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论