mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat: add QueryIntWithDefault to web context (#93130)
This commit is contained in:
parent
22c63ea3c5
commit
2c93120a42
@ -182,12 +182,22 @@ func (ctx *Context) QueryInt(name string) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// QueryIntWithDefault returns query result in int type, including a default when the query param is not a valid int.
|
||||
func (ctx *Context) QueryIntWithDefault(name string, d int) int {
|
||||
n, err := strconv.Atoi(ctx.Query(name))
|
||||
if err != nil {
|
||||
return d
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// QueryInt64 returns query result in int64 type.
|
||||
func (ctx *Context) QueryInt64(name string) int64 {
|
||||
n, _ := strconv.ParseInt(ctx.Query(name), 10, 64)
|
||||
return n
|
||||
}
|
||||
|
||||
// QueryInt64WithDefault returns query result in int64 type, including a default when the query param is not a valid int64.
|
||||
func (ctx *Context) QueryInt64WithDefault(name string, d int64) int64 {
|
||||
n, err := strconv.ParseInt(ctx.Query(name), 10, 64)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user