AppEngine/Go应用无法编译。我错过了什么?

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

AppEngine/Go app won't compile. What did I miss?

问题

我正在尝试测试一个AppEngine/Go应用程序。我启动dev_appserver.py并开始提供应用程序,但是当我在浏览器中输入localhost:8080时,我得到以下错误信息:

编译错误:
/home/adam/foobar/server/app/server.go:5: 找不到导入:appengine/users

2011/08/23 19:45:34 go-app-builder: 构建应用程序失败:运行8g失败:退出状态1

我感觉我需要做一些事情,以使AppEngine特定的库在GO期望它们存在的位置可用,但是我真的不想在AppEngine/Go SDK压缩包中的所有内容上运行goinstall,对吗?我似乎错过了一个安装步骤,但是就我而言,我无法找到明智和正确的做法。

我使用的是Ubuntu,如果这有关系的话。

英文:

I am trying to test an AppEngine/Go application. I start dev_appserver.py and it begins serving the application, but when I go to localhost:8080 in my browser, I get:

Compile error:
/home/adam/foobar/server/app/server.go:5: can't find import: appengine/users

2011/08/23 19:45:34 go-app-builder: Failed building app: failed running 8g: exit status 1

I feel as though I need to do something to make the AppEngine-specific libraries available where GO expects them to be, but I don't really want to run goinstall on everything that comes in the AppEngine/Go SDK zip, do I? I seem to have missed an installation step, but for the life of me, I can't figure the sane and right thing to do.

I am on Ubuntu, if that matters.

答案1

得分: 9

用户API不是appengine/users,而是appengine/user。从App Engine页面的示例中可以看到:

import (
    "appengine"
    "appengine/user"
)

func welcome(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    u := user.Current(c)
    if u == nil {
        url := u.LoginURL(c, "/")
        fmt.Fprintf(w, `<a href="%s">登录或注册</a>`, url)
        return
    }
    url := user.LogoutURL(c, "/")
    fmt.Fprintf(w, `欢迎,%s!(<a href="%s">退出</a>)`, u, url)
}
英文:

The Users API isn't appengine/users - it's appengine/user. From the example on the App Engine page:

import (
    &quot;appengine&quot;
    &quot;appengine/user&quot;
)

func welcome(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    u := user.Current(c)
    if u == nil {
        url := u.LoginURL(c, &quot;/&quot;)
        fmt.Fprintf(w, `&lt;a href=&quot;%s&quot;&gt;Sign in or register&lt;/a&gt;`, url)
        return
    }
    url := user.LogoutURL(c, &quot;/&quot;)
    fmt.Fprintf(w, `Welcome, %s! (&lt;a href=&quot;%s&quot;&gt;sign out&lt;/a&gt;)`, u, url)
}

答案2

得分: 0

你不需要自己编译代码 - 只需运行dev_appserver,它会在代码更改时为您编译。您是否已经阅读了入门文档

英文:

You don't have to compile the code yourself - just run the dev_appserver and it will compile it for you whenever the code changes. Have you gone through the getting started docs?

huangapple
  • 本文由 发表于 2011年8月24日 07:51:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/7168879.html
匿名

发表评论

匿名网友

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

确定