mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 06:42:10 +08:00
update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
6a7a41b634
commit
5b57025f80
16
context.go
16
context.go
@ -53,8 +53,6 @@ type Context struct {
|
||||
|
||||
engine *Engine
|
||||
|
||||
EnableMutexLock bool
|
||||
|
||||
// This mutex protect Keys map
|
||||
mu sync.RWMutex
|
||||
|
||||
@ -235,27 +233,21 @@ func (c *Context) Error(err error) *Error {
|
||||
// Set is used to store a new key/value pair exclusively for this context.
|
||||
// It also lazy initializes c.Keys if it was not used previously.
|
||||
func (c *Context) Set(key string, value interface{}) {
|
||||
if c.EnableMutexLock {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
if c.Keys == nil {
|
||||
c.Keys = make(map[string]interface{})
|
||||
}
|
||||
|
||||
c.Keys[key] = value
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
// Get returns the value for the given key, ie: (value, true).
|
||||
// If the value does not exists it returns (nil, false)
|
||||
func (c *Context) Get(key string) (value interface{}, exists bool) {
|
||||
if c.EnableMutexLock {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
}
|
||||
|
||||
c.mu.RLock()
|
||||
value, exists = c.Keys[key]
|
||||
c.mu.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user