Add URLParamInt64 as requested by the community on chat

This commit is contained in:
Makis Maropoulos 2016-06-26 08:44:10 +03:00
parent 57ba8e89b5
commit 132021ec43
2 changed files with 8 additions and 3 deletions

View File

@ -170,8 +170,7 @@ func (ctx *Context) Param(key string) string {
// ParamInt returns the int representation of the key's path named parameter's value
func (ctx *Context) ParamInt(key string) (int, error) {
val, err := strconv.Atoi(ctx.Param(key))
return val, err
return strconv.Atoi(ctx.Param(key))
}
// URLParam returns the get parameter from a request , if any
@ -188,11 +187,16 @@ func (ctx *Context) URLParams() map[string]string {
return urlparams
}
// URLParamInt returns the get parameter int value from a request , if any
// URLParamInt returns the url query parameter as int value from a request , returns error on parse fail
func (ctx *Context) URLParamInt(key string) (int, error) {
return strconv.Atoi(ctx.URLParam(key))
}
// URLParamInt64 returns the url query parameter as int64 value from a request , returns error on parse fail
func (ctx *Context) URLParamInt64(key string) (int64, error) {
return strconv.ParseInt(ctx.Param(key), 10, 64)
}
// MethodString returns the HTTP Method
func (ctx *Context) MethodString() string {
return utils.BytesToString(ctx.Method())

View File

@ -18,6 +18,7 @@ type (
ParamInt(string) (int, error)
URLParam(string) string
URLParamInt(string) (int, error)
URLParamInt64(string) (int64, error)
URLParams() map[string]string
MethodString() string
HostString() string