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

Unified Diff: go/src/infra/gae/libs/wrapper/memory/globalinfo.go

Issue 1152383003: Simple memory testing for gae/wrapper (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@better_context_lite
Patch Set: add go-slab dependency Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
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..2d3027271e6d9ccf56eb3412fcb4a25d7c2c7329
--- /dev/null
+++ b/go/src/infra/gae/libs/wrapper/memory/globalinfo.go
@@ -0,0 +1,41 @@
+// 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 (
+ "infra/gae/libs/wrapper"
+
+ "golang.org/x/net/context"
+)
+
+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}
+ })
+}
+
+type globalInfoData struct{ namespace string }
+
+type giImpl struct {
+ wrapper.GlobalInfo
+ data *globalInfoData
+ c context.Context
+}
+
+var _ = wrapper.GlobalInfo((*giImpl)(nil))
+
+func (gi *giImpl) Namespace(ns string) (context.Context, error) {
+ return context.WithValue(gi.c, giContextKey, &globalInfoData{ns}), nil
+}
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/gkvlite_utils.go ('k') | go/src/infra/gae/libs/wrapper/memory/internal/goon/goon.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698