英文:
Creating API backend on App Engine
问题
我想为使用Go的App Engine上的应用程序创建一个REST后端。
我已经按照以下方式安排了我的文件:
-> app/
-> auth/
-> auth.go
-> app.go
-> app.yaml
通常情况下,我会在app.go中使用import "github.com/user/app/auth"
导入auth包,但是我收到一个错误,说文件之间存在冲突(我现在无法粘贴错误)。
在Google上寻找解决方案后,我发现如果我删除github.com...,只使用import "auth"
,它就可以工作,而且确实可以。
上述解决方案是最好的修复方法吗?
英文:
I would like to create a rest backend for an application on App Engine using Go.
I have arranged my files as fallow:
-> app/
-> auth/
-> auth.go
-> app.go
-> app.yaml
Normally I would import the auth package in app.go with: import "github.com/user/app/auth"
, but I get an error saying that there is a conflict between files(I can't paste the error right now).
After looking for a solution on google I've found out that if I remove the github.com... and just import "auth"
it will work, and it does.
Is the solution above the best fix?
答案1
得分: 2
错误是否类似于Failed parsing input: app file auth/auth.go conflicts with same file imported from GOPATH
?
根据我阅读的https://groups.google.com/forum/#!msg/google-appengine-go/dNhqV6PBqVc/ihzI5vgdE1EJ,现在最好安排你的文件,以便你可以使用github.com/user/...
导入。这是由于SDK 1.9.1的新行为破坏了一些项目布局。使用import "auth"
大部分情况下可以工作,但它会破坏goapp test
并可能引起其他问题。
相反,你可以确保在app.yaml
和app.go
的级别或以下没有其他go代码。为此,你可以将auth
上移两个级别,到app
的父级,并将其作为github.com/user/auth
导入。如果你可能在其他应用程序中使用相同的代码,那么这是有意义的。
-> app/
-> app.go
-> app.yaml
-> auth/
-> auth.go
或者将auth
上移一个级别,并将yaml和app.go
移动到一个子目录中。如果你这样做,你将不得不进入该目录来运行goapp server
,因为那里有app.yaml
。
-> app/
-> auth/
-> auth.go
-> app/
-> app.go
-> app.yaml
无论哪种方式,与app.yaml
相同目录下应该只有一个*.go
文件。
英文:
Was the error something like Failed parsing input: app file auth/auth.go conflicts with same file imported from GOPATH
?
My reading of https://groups.google.com/forum/#!msg/google-appengine-go/dNhqV6PBqVc/ihzI5vgdE1EJ is that it's now better to arrange your files so that you can use the github.com/user/...
import. This is due to new behavior with SDK 1.9.1 that breaks some project layouts. Using import "auth"
will mostly work, but it breaks goapp test
and may cause other problems.
Instead the idea is to make sure that there isn't any other go code at or under the level of your app.yaml
and app.go
. To do this you could move auth
up two levels, to the parent of app
, and import it as github.com/user/auth
. That would make sense if you might use that same code in other apps.
-> app/
-> app.go
-> app.yaml
-> auth/
-> auth.go
Or move auth
up one level, and move the yaml and app.go
into a subdirectory. If you do that you'll have to cd into that directory to run goapp server
, because that's where the app.yaml
is.
-> app/
-> auth/
-> auth.go
-> app/
-> app.go
-> app.yaml
Either way, there should be only one *.go
file in the same directory as the app.yaml
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论