在从ctx, ctxErr := appengine.Namespace(ctx, "MyContext")获得上下文之后,我希望ctx名称空间中填充MyContext
码
import (
...
"golang.org/x/net/context"
"google.golang.org/appengine"
)
ctx := appengine.NewContext(r)
ctx, ctxErr := appengine.Namespace(ctx, "MyContext")
if ctxErr != nil {
log.Errorf(ctx, "Failed to obtain custom namespace context, error:%s", ctxErr.Error())
//use default if all else fails
ctx = appengine.NewContext(r)
}然而,情况并非如此,从而导致所有命名空间感知API都使用默认名称空间。
ctx的转储产生以下结果(参见黄色边框输出)

示例应用程序
用项目id填充projectID := "",确保您在开发环境上执行了身份验证,并运行了go run /example/app/main.go。
发布于 2016-12-13 22:56:43
https://stackoverflow.com/questions/41061803
复制相似问题