Google App Engine模块主机名:不是App Engine上下文 [英] Google App Engine ModuleHostname: not an App Engine context

查看:69
本文介绍了Google App Engine模块主机名:不是App Engine上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在App Engine上发现其他已部署的服务.文章类似.

I am trying to discover other deployed services on the App Engine. Something like this article suggests.

这是我的代码的样子:

import (
    "fmt"
    "net/http"

    "google.golang.org/appengine"
)

func ServiceHostname(serviceName string, r *http.Request) (string, error) {
    ctx := appengine.NewContext(r)
    hostname, err := appengine.ModuleHostname(ctx, serviceName, "", "")
    if err != nil {
        return "", fmt.Errorf("unable to find service %s: %v", serviceName, err)
    }
    return hostname, nil
}

我在常规的http处理程序中调用此函数.我遇到的错误是:不是App Engine上下文.

I am calling this function in a regular http handler. The error I've got is: not an App Engine context.

我的代码和所引用文章之间的唯一区别是App Engine Go版本.我正在使用新的 go111 ,其中他正在使用 go1 运行时.

The only difference in between my code and the referenced article is in app engine go version. I am using the new go111 where he's using go1 runtime.

您知道如何解决该问题吗?

Do you know how to overcome the issue?

推荐答案

我找到了解决方案.即使不需要在新的 go111 运行时中进行操作,您也需要在主文件中调用 appengine.Main().

I found the solution. You need to call appengine.Main() in your main file even though it shouldn't be necessary to do in the new go111 runtime.

因此所讨论的代码保持不变,您需要在 go1.9 运行时中注册您的处理程序.

So the code in question stays the same, you need to register your handlers same as in go1.9 runtime.

func main() {
    http.HandleFunc("/serveurl", handle)
    appengine.Main()
}

来源: https://groups.google.com/d/msg/google-appengine-go/ZcASFMWJKpE/7iwGirNiBgAJ

编写主程序包:

  • 或者,如果您的服务使用的是 google.golang.org/appengine 包,请包含对 appengine.Main()的调用.
  • Or, if your service is using the google.golang.org/appengine package, include a call to appengine.Main().

这篇关于Google App Engine模块主机名:不是App Engine上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆