亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Google App Engine context.Context

Google App Engine context.Context

Go
LEATH 2021-12-07 15:20:47
在 GAE Go 中,為了記錄,我們需要創建一個新的上下文,使用appengine.NewContext(r)which returns context.Context。如何使用此上下文在請求范圍內設置/獲取變量?在 Gorilla 中,Context在上下文中有一個干凈的 Set/Get 函數,這是我想在我的代碼中使用的。但是我不想導入 2 個不同的上下文包。GAE 日志記錄強制您使用context.Context.//handlerFuncfunc 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?}
查看完整描述

1 回答

?
縹緲止盈

TA貢獻2041條經驗 獲得超4個贊

import (

    "golang.org/x/net/context"

    gorillacontext "github.com/gorilla/context"    

)

我知道這是不是你想要的答案,但有沒有辦法解決它,因為“背景下的圍棋標準庫(由App Engine的使用)”包不提供你想要比大猩猩“的功能范圍內”包. 如果要使用定義自己的“上下文”包的其他框架,則需要使用多個導入。


在小組討論中對這兩個上下文提出了一個很好的觀點,因為可能 Gorilla 的上下文被錯誤命名,因為它們都用于不同的目的——“App Engine 一個存儲憑據以發出 RPC 請求;Gorilla 一個只是請求的容器全球性?!?/p>


查看完整回答
反對 回復 2021-12-07
  • 1 回答
  • 0 關注
  • 170 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號