mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 13:02:14 +08:00
Implemented GetDefault
This commit is contained in:
parent
3b079bb6f7
commit
e600055457
15
context.go
15
context.go
@ -8,11 +8,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
"github.com/gin-gonic/gin/render"
|
"github.com/gin-gonic/gin/render"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -185,6 +186,16 @@ func (c *Context) MustGet(key string) interface{} {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefault returns the value for the given key or a default value if the key does not exist.
|
||||||
|
func (c *Context) GetDefault(key string, defaultVal interface{}) interface{} {
|
||||||
|
item, err := c.Get(key)
|
||||||
|
if err != nil {
|
||||||
|
return defaultVal
|
||||||
|
}
|
||||||
|
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
/******** ENCOGING MANAGEMENT********/
|
/******** ENCOGING MANAGEMENT********/
|
||||||
/************************************/
|
/************************************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user