Index: impl/memory/info.go |
diff --git a/impl/memory/info.go b/impl/memory/info.go |
index 6d28d5ab45478255432528ab560d1442b1c8b766..432f70195ee82efab6f464cde55b466392c049af 100644 |
--- a/impl/memory/info.go |
+++ b/impl/memory/info.go |
@@ -20,23 +20,46 @@ var giContextKey giContextKeyType |
// validNamespace matches valid namespace names. |
var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`) |
+var defaultGlobalInfoData = globalInfoData{ |
+ // versionID returns X.Y where Y is autogenerated by appengine, and X is |
+ // whatever's in app.yaml. |
+ versionID: "testVersionID.1", |
+ requestID: "test-request-id", |
+} |
+ |
+type globalInfoData struct { |
+ appid string |
+ namespace string |
+ versionID string |
+ requestID string |
+} |
+ |
func curGID(c context.Context) *globalInfoData { |
- return c.Value(giContextKey).(*globalInfoData) |
+ if gid, ok := c.Value(giContextKey).(*globalInfoData); ok { |
+ return gid |
+ } |
+ return &defaultGlobalInfoData |
+} |
+ |
+func useGID(c context.Context, f func(mod *globalInfoData)) context.Context { |
+ cur := curGID(c) |
+ if cur == nil { |
+ cur = &defaultGlobalInfoData |
+ } |
+ |
+ clone := *cur |
+ f(&clone) |
+ return context.WithValue(c, giContextKey, &clone) |
} |
// useGI adds a gae.GlobalInfo context, accessible |
// by gae.GetGI(c) |
-func useGI(c context.Context, appID string) context.Context { |
+func useGI(c context.Context) context.Context { |
return info.SetFactory(c, func(ic context.Context) info.Interface { |
return &giImpl{dummy.Info(), curGID(ic), ic} |
}) |
} |
-type globalInfoData struct { |
- appid string |
- namespace string |
-} |
- |
type giImpl struct { |
info.Interface |
*globalInfoData |
@@ -53,7 +76,10 @@ func (gi *giImpl) Namespace(ns string) (ret context.Context, err error) { |
if !validNamespace.MatchString(ns) { |
return nil, fmt.Errorf("appengine: namespace %q does not match /%s/", ns, validNamespace) |
} |
- return context.WithValue(gi.c, giContextKey, &globalInfoData{gi.appid, ns}), nil |
+ |
+ return useGID(gi.c, func(mod *globalInfoData) { |
+ mod.namespace = ns |
+ }), nil |
} |
func (gi *giImpl) MustNamespace(ns string) context.Context { |
@@ -77,7 +103,25 @@ func (gi *giImpl) IsDevAppServer() bool { |
} |
func (gi *giImpl) VersionID() string { |
- // VersionID returns X.Y where Y is autogenerated by appengine, and X is |
- // whatever's in app.yaml. |
- return "testVersionID.1" |
+ return curGID(gi.c).versionID |
+} |
+ |
+func (gi *giImpl) RequestID() string { |
+ return curGID(gi.c).requestID |
+} |
+ |
+func (gi *giImpl) Testable() info.Testable { |
+ return gi |
+} |
+ |
+func (gi *giImpl) SetVersionID(v string) context.Context { |
+ return useGID(gi.c, func(mod *globalInfoData) { |
+ mod.versionID = v |
+ }) |
+} |
+ |
+func (gi *giImpl) SetRequestID(v string) context.Context { |
+ return useGID(gi.c, func(mod *globalInfoData) { |
+ mod.requestID = v |
+ }) |
} |