Skip to content
Myr

update context.go Get/Set method use defer (#3429)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Using defer to unlock is more in line with go standards

authored by youngxhui · committed by GitHub · parent 41f2669 · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:context.go+2 added-2 removed
246 unmodified lines
247// Set is used to store a new key/value pair exclusively for this context.248// It also lazy initializes c.Keys if it was not used previously.249func (c *Context) Set(key string, value any) {250 c.mu.Lock()251 defer c.mu.Unlock()252 if c.Keys == nil {253 c.Keys = make(map[string]any)254 }255256 c.Keys[key] = value256 c.mu.Unlock()257}258259// Get returns the value for the given key, ie: (value, true).260// If the value does not exist it returns (nil, false)261func (c *Context) Get(key string) (value any, exists bool) {262 c.mu.RLock()263 defer c.mu.RUnlock()264 value, exists = c.Keys[key]264 c.mu.RUnlock()265 return266}267268// MustGet returns the value for the given key if it exists, otherwise it panics.
950 unmodified lines