英文:
How to import local Go package in GAE
问题
如何在Golang + GAE中导入本地包?
我想要像这样的结构:
app/
-app.yaml
-/my_app
--my_app.go
--/package1
---package1.go
my_app.go的代码如下:
package my_app
import (
"http"
"./package1"
)
func init() {
http.HandleFunc("/", package1.index)
}
package1.go的代码如下:
package package1
import (
"http"
"fmt"
)
func index (w http.ResponseWriter, r * http.Request) {
fmt.Fprint(w, "I'm index page =)")
}
在这种情况下,我遇到了以下错误:
/path/to/project/my_app/my_app.go:5: can't find import: ./package1
2011/11/03 10:50:51 go-app-builder: Failed building app: failed running 6g: exit status 1
谢谢帮助。
英文:
How to import local packages in Golang + GAE?
I wanna something like this:
app/
-app.yaml
-/my_app
--my_app.go
--/package1
---package1.go
Listing of my_app.go:
package my_app
import (
"http"
"./package1"
)
func init() {
http.HandleFunc("/", package1.index)
}
Listing of package1.go:
package package1
import (
"http"
"fmt"
)
func index (w http.ResponseWriter, r * http.Request) {
fmt.Fprint(w, "I'm index page =) ")
}
I this case I have an error like:
/path/to/project/my_app/my_app.go:5: can't find import: ./package1
2011/11/03 10:50:51 go-app-builder: Failed building app: failed running 6g: exit status 1
Thanks for help.
答案1
得分: 6
如dupoxy的回答中所指出的,导入本地包的方法是使用"my_app/package1"
进行导入:
import (
"http"
"my_app/package1"
)
英文:
As noted in the comments to dupoxy's answer, the way to import a local package in the given situation is to import as "my_app/package1"
:
import (
"http"
"my_app/package1"
)
答案2
得分: 1
你需要将包链接或复制到你的应用程序目录中。相对于应用程序目录的路径应该与导入路径匹配。要使用package1,你应该将你的应用程序目录配置成这样:
app.yaml
yourapp/yourapp.go
package1/package1.go
来源:https://groups.google.com/d/msg/golang-nuts/coEvrWIJGTs/75GzcefKVcIJ
英文:
<strike>You either need to link or copy the packages to your application directory.</strike> The path relative to the root of the application directory should match the import path.<strike> To use package1, you should configure your app directory to look like this:
app.yaml
yourapp/yourapp.go
package1/package1.go
</strike>
from https://groups.google.com/d/msg/golang-nuts/coEvrWIJGTs/75GzcefKVcIJ
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论