mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
fix missing initial sync.RWMutex
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
bd5ee1aae2
commit
ba621af762
@ -224,6 +224,10 @@ 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.KeysMutex == nil {
|
||||
c.KeysMutex = &sync.RWMutex{}
|
||||
}
|
||||
|
||||
c.KeysMutex.Lock()
|
||||
if c.Keys == nil {
|
||||
c.Keys = make(map[string]interface{})
|
||||
@ -236,6 +240,10 @@ func (c *Context) Set(key string, value interface{}) {
|
||||
// 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.KeysMutex == nil {
|
||||
c.KeysMutex = &sync.RWMutex{}
|
||||
}
|
||||
|
||||
c.KeysMutex.RLock()
|
||||
value, exists = c.Keys[key]
|
||||
c.KeysMutex.RUnlock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user