This commit is contained in:
crusader 2017-11-27 19:58:54 +09:00
parent 0eefc4bd27
commit 596477790f

View File

@ -10,7 +10,7 @@ func (c ContextKey) String() string {
func NewContext(parent Context) Context { func NewContext(parent Context) Context {
c := &defaultContext{ c := &defaultContext{
parent: parent, Context: parent,
} }
c.attributes = make(map[string]interface{}) c.attributes = make(map[string]interface{})
@ -25,7 +25,7 @@ type Context interface {
} }
type defaultContext struct { type defaultContext struct {
parent Context Context
attributes map[string]interface{} attributes map[string]interface{}
mtx sync.RWMutex mtx sync.RWMutex
@ -50,10 +50,10 @@ func (dc *defaultContext) GetAttribute(key string) (value interface{}) {
return dc.attributes[key] return dc.attributes[key]
} }
if nil == dc.parent { if nil == dc.Context {
return nil return nil
} }
return dc.parent.GetAttribute(key) return dc.Context.GetAttribute(key)
} }
func (dc *defaultContext) RemoveAttribute(key string) { func (dc *defaultContext) RemoveAttribute(key string) {
@ -67,11 +67,11 @@ func (dc *defaultContext) RemoveAttribute(key string) {
return return
} }
if nil == dc.parent { if nil == dc.Context {
return return
} }
dc.parent.RemoveAttribute(key) dc.Context.RemoveAttribute(key)
} }
func (dc *defaultContext) ContainsAttribute(key string) (exist bool) { func (dc *defaultContext) ContainsAttribute(key string) (exist bool) {
@ -84,10 +84,10 @@ func (dc *defaultContext) ContainsAttribute(key string) (exist bool) {
return true return true
} }
if nil == dc.parent { if nil == dc.Context {
return false return false
} }
return dc.parent.ContainsAttribute(key) return dc.Context.ContainsAttribute(key)
} }
func (dc *defaultContext) checkInitialized() { func (dc *defaultContext) checkInitialized() {