Update context.go

use method Get to get existing data.
This commit is contained in:
Cheikh Seck 2022-09-19 12:06:54 +00:00 committed by GitHub
parent 84bae816a0
commit 0d9e3d19af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -268,13 +268,11 @@ func (c *Context) Get(key string) (value any, exists bool) {
// GetAs returns the value for the given key, ie: (value, true).
// If the value does not exist it returns (nil, false)
func (c *Context) GetAs[T any](key string) (result T, exists bool) {
c.mu.RLock()
value, exists := c.Keys[key]
c.mu.RUnlock()
value, exists := c.Get(key)
if !exists {
return
}
result, exists = value.(T)
return
}