Add ParamInt64 as requested on chat from the community

This commit is contained in:
Makis Maropoulos 2016-06-26 08:46:04 +03:00
parent 132021ec43
commit abccf7fc06
2 changed files with 7 additions and 1 deletions

View File

@ -173,6 +173,11 @@ func (ctx *Context) ParamInt(key string) (int, error) {
return strconv.Atoi(ctx.Param(key))
}
// ParamInt64 returns the int64 representation of the key's path named parameter's value
func (ctx *Context) ParamInt64(key string) (int64, error) {
return strconv.ParseInt(ctx.Param(key), 10, 64)
}
// URLParam returns the get parameter from a request , if any
func (ctx *Context) URLParam(key string) string {
return string(ctx.RequestCtx.Request.URI().QueryArgs().Peek(key))
@ -194,7 +199,7 @@ func (ctx *Context) URLParamInt(key string) (int, error) {
// 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)
return strconv.ParseInt(ctx.URLParam(key), 10, 64)
}
// MethodString returns the HTTP Method

View File

@ -16,6 +16,7 @@ type (
IContext interface {
Param(string) string
ParamInt(string) (int, error)
ParamInt64(string) (int64, error)
URLParam(string) string
URLParamInt(string) (int, error)
URLParamInt64(string) (int64, error)