LoginSignup
2
0

More than 5 years have passed since last update.

GAE/Go1.8のcontext問題

Last updated at Posted at 2017-12-10

問題

GAEのcontextを取得する際、公式のサンプルでは以下のように取得しています。

import "google.golang.org/appengine"

func handler(w http.ResponseWriter, r *http.Request) {
    ctx := appengine.NewContext(r)
}

しかしapiバージョンがgo1.8の場合は以下のようなエラーが出ると思います。

appengine: NewContext passed an unknown http.Request

これは、Go1.7で標準パッケージにcontextパッケージが追加されたことによる問題です。

解決策

以下のようにContextメソッドを使用することで、リクエストにスコープされたコンテキストを取得することが出来ます。

func handler(w http.ResponseWriter, r *http.Request) {
    ctx := r.Context()
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0