Chromium Code Reviews| Index: go/src/infra/gae/libs/wrapper/memory/globalinfo.go |
| diff --git a/go/src/infra/gae/libs/wrapper/memory/globalinfo.go b/go/src/infra/gae/libs/wrapper/memory/globalinfo.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9c580346a065b977c97e319cb4a01dd4faeb64f3 |
| --- /dev/null |
| +++ b/go/src/infra/gae/libs/wrapper/memory/globalinfo.go |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package memory |
| + |
| +import ( |
| + "golang.org/x/net/context" |
| + |
| + "infra/gae/libs/wrapper" |
| +) |
| + |
| +type giContextKeyType int |
| + |
| +var giContextKey giContextKeyType |
| + |
| +func curGID(c context.Context) *globalInfoData { |
| + return c.Value(giContextKey).(*globalInfoData) |
| +} |
| + |
| +// UseGI adds a wrapper.GlobalInfo context, accessible |
| +// by wrapper.GetGI(c) |
| +func UseGI(c context.Context) context.Context { |
| + return wrapper.SetGIFactory(c, func(ic context.Context) wrapper.GlobalInfo { |
| + return &giImpl{wrapper.DummyGI(), curGID(ic), ic} |
| + }) |
| +} |
| + |
| +func newGlobalInfoData() *globalInfoData { |
| + return &globalInfoData{namespace: ""} |
| +} |
| + |
| +type globalInfoData struct{ namespace string } |
| + |
| +type giImpl struct { |
| + wrapper.GlobalInfo |
| + data *globalInfoData |
| + c context.Context |
| +} |
| + |
| +func (gi *giImpl) Namespace(ns string) (context.Context, error) { |
|
iannucci
2015/05/24 20:33:54
I only implement Namespace for now because it inte
|
| + return context.WithValue(gi.c, giContextKey, &globalInfoData{ns}), nil |
| +} |