gpt4 book ai didi

google-app-engine - Google App Engine 模块主机名 : not an App Engine context

转载 作者:IT王子 更新时间:2023-10-29 01:53:45 26 4
gpt4 key购买 nike

我正在尝试发现 App Engine 上的其他已部署服务。类似于 this文章建议。

我的代码是这样的:

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 上下文

我的代码与引用文章之间的唯一区别在于 App Engine Go 版本。我正在使用新的 go111 而他正在使用 go1 运行时。

你知道如何克服这个问题吗?

最佳答案

我找到了解决方案。您需要在主文件中调用 appengine.Main(),即使在新的 go111 运行时中没有必要这样做。

所以有问题的代码保持不变,您需要像在 go1.9 运行时一样注册您的处理程序。

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

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

Writing a main package 中也提到了它:

  • Or, if your service is using the google.golang.org/appengine package, include a call to appengine.Main().

关于google-app-engine - Google App Engine 模块主机名 : not an App Engine context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53801551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com