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 memory | |
6 | |
7 import ( | |
8 "golang.org/x/net/context" | |
9 | |
10 "infra/gae/libs/wrapper" | |
11 ) | |
12 | |
13 type giContextKeyType int | |
14 | |
15 var giContextKey giContextKeyType | |
16 | |
17 func curGID(c context.Context) *globalInfoData { | |
18 return c.Value(giContextKey).(*globalInfoData) | |
19 } | |
20 | |
21 // UseGI adds a wrapper.GlobalInfo context, accessible | |
22 // by wrapper.GetGI(c) | |
23 func UseGI(c context.Context) context.Context { | |
24 return wrapper.SetGIFactory(c, func(ic context.Context) wrapper.GlobalIn fo { | |
25 return &giImpl{wrapper.DummyGI(), curGID(ic), ic} | |
26 }) | |
27 } | |
28 | |
29 func newGlobalInfoData() *globalInfoData { | |
30 return &globalInfoData{namespace: ""} | |
M-A Ruel
2015/05/25 18:21:09
return &globalInfoData{}
Then, why this function
iannucci
2015/05/27 19:33:32
because I dumbs
| |
31 } | |
32 | |
33 type globalInfoData struct{ namespace string } | |
34 | |
35 type giImpl struct { | |
36 wrapper.GlobalInfo | |
37 data *globalInfoData | |
38 c context.Context | |
39 } | |
40 | |
41 func (gi *giImpl) Namespace(ns string) (context.Context, error) { | |
42 return context.WithValue(gi.c, giContextKey, &globalInfoData{ns}), nil | |
43 } | |
OLD | NEW |