| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package gae | |
| 6 | |
| 7 import ( | |
| 8 "errors" | |
| 9 "golang.org/x/net/context" | |
| 10 | |
| 11 "appengine" | |
| 12 | |
| 13 "github.com/mjibson/goon" | |
| 14 ) | |
| 15 | |
| 16 // Use adds implementations for the following gae/wrapper interfaces to the | |
| 17 // context: | |
| 18 // * wrapper.Datastore | |
| 19 // * wrapper.TaskQueue | |
| 20 // * wrapper.Memcache | |
| 21 // * wrapper.GlobalInfo | |
| 22 // | |
| 23 // These can be retrieved with the "gae/wrapper".Get functions. | |
| 24 // | |
| 25 // The implementations are all backed by the real "appengine" SDK functionality, | |
| 26 // and by "github.com/mjibson/goon". | |
| 27 // | |
| 28 // Using this more than once per context.Context will cause a panic. | |
| 29 func Use(c context.Context, gaeCtx appengine.Context) context.Context { | |
| 30 if c.Value(goonContextKey) != nil { | |
| 31 panic(errors.New("gae.Use: called twice on the same Context")) | |
| 32 } | |
| 33 c = context.WithValue(c, goonContextKey, goon.FromContext(gaeCtx)) | |
| 34 return useDS(useMC(useTQ(useGI(c)))) | |
| 35 } | |
| 36 | |
| 37 type key int | |
| 38 | |
| 39 var goonContextKey key | |
| 40 | |
| 41 func ctx(c context.Context) *goon.Goon { | |
| 42 return c.Value(goonContextKey).(*goon.Goon) | |
| 43 } | |
| OLD | NEW |