Skip to content

Commit

Permalink
Move context once to instanceContext from global scope
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen J Day <[email protected]>
  • Loading branch information
stevvooe committed Jul 30, 2015
1 parent 6086124 commit c737d19
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c737d19

Please sign in to comment.