From c737d19235181760ce2d6df3b57ea44864e81af8 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 30 Jul 2015 13:59:44 -0700 Subject: [PATCH] Move context once to instanceContext from global scope Signed-off-by: Stephen J Day --- context/context.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/context/context.go b/context/context.go index 07b844ef0..23cbf5b54 100644 --- a/context/context.go +++ b/context/context.go @@ -7,10 +7,6 @@ import ( "golang.org/x/net/context" ) -var ( - once sync.Once -) - // Context is a copy of Context from the golang.org/x/net/context package. type Context interface { context.Context @@ -20,12 +16,13 @@ type Context interface { // provided as the main background context. type instanceContext struct { Context - id string // id of context, logged as "instance.id" + id string // id of context, logged as "instance.id" + once sync.Once // once protect generation of the id } func (ic *instanceContext) Value(key interface{}) interface{} { if key == "instance.id" { - once.Do(func() { + ic.once.Do(func() { // We want to lazy initialize the UUID such that we don't // call a random generator from the package initialization // code. For various reasons random could not be available