Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: go/src/infra/gae/libs/context/goon.go

Issue 981003003: Simple GAE/goon Context wrapper (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: skip testing for context Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/src/infra/gae/libs/context/doc.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // +build appengine
6
7 package context
8
9 import (
10 "appengine"
11 "appengine/datastore"
12
13 "github.com/mjibson/goon"
14 )
15
16 type goonWrapper struct{ *goon.Goon }
17
18 // FromGoon creates a DangerousTransactionerContext backed by an existing
19 // *goon.Goon
20 func FromGoon(c *goon.Goon) DangerousTransactionerContext {
21 return goonWrapper{c}
22 }
23
24 // GoonFromContext creates a DangerousTransactionerContext backed by the
25 // github.com/mjibson/goon library.
26 func GoonFromContext(c appengine.Context) DangerousTransactionerContext {
27 return goonWrapper{goon.FromContext(c)}
28 }
29
30 // logger
31 func (g goonWrapper) Debugf(format string, args ...interface{}) {
32 g.Goon.Context.Debugf(format, args...)
33 }
34
35 func (g goonWrapper) Infof(format string, args ...interface{}) {
36 g.Goon.Context.Infof(format, args...)
37 }
38
39 func (g goonWrapper) Warningf(format string, args ...interface{}) {
40 g.Goon.Context.Warningf(format, args...)
41 }
42
43 func (g goonWrapper) Errorf(format string, args ...interface{}) {
44 g.Goon.Context.Errorf(format, args...)
45 }
46
47 // Kinder
48 func (g goonWrapper) KindNameResolver() goon.KindNameResolver {
49 return g.Goon.KindNameResolver
50 }
51
52 func (g goonWrapper) SetKindNameResolver(knr goon.KindNameResolver) {
53 g.Goon.KindNameResolver = knr
54 }
55
56 // NewKeyer
57 func (g goonWrapper) NewKey(kind, stringID string, intID int64, parent *datastor e.Key) *datastore.Key {
58 return datastore.NewKey(g.Goon.Context, kind, stringID, intID, parent)
59 }
60
61 func (g goonWrapper) NewKeyObj(obj interface{}) *datastore.Key {
62 return g.Key(obj)
63 }
64
65 func (g goonWrapper) NewKeyObjError(obj interface{}) (*datastore.Key, error) {
66 return g.KeyError(obj)
67 }
68
69 // Queryer
70 func (g goonWrapper) Run(q *datastore.Query) Iterator {
71 return g.Run(q)
72 }
73
74 // Transactioner
75 func (g goonWrapper) RunInTransaction(f func(c Context) error, opts *datastore.T ransactionOptions) error {
76 return g.Goon.RunInTransaction(func(ig *goon.Goon) error {
77 return f(Context(FromGoon(ig)))
78 }, opts)
79 }
80
81 // Contexter
82 func (g goonWrapper) Context() appengine.Context {
83 return g.Goon.Context
84 }
OLDNEW
« no previous file with comments | « go/src/infra/gae/libs/context/doc.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698