在GAE围棋,为了记录,我们需要创建一个使用新的上下文appengine.NewContext(r)
返回context.Context
。
如何使用此上下文在请求范围内设置/获取变量?在Gorilla中,Context在上下文中具有干净的Set / Get函数,这是我想在代码中使用的功能。但是,我不想导入2个不同的上下文包。
GAE日志记录迫使您使用context.Context
。
//handlerFunc
func MyFunc(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
// I want to set request scoped variables in context and pass it to doSomething.
doSomething(ctx,w,r);
}
func doSomething(ctx context.Context, w http.ResponseWriter, r *http.Request) {
log.Debugf(ctx, "Beginning doSomething"); //requires context parameter
// get the request scoped variables from context. How? Use Gorilla Context?
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句