mirror of
https://github.com/nkanaev/yarr.git
synced 2025-12-15 16:40:04 +00:00
context int shorthands
This commit is contained in:
@@ -2,8 +2,10 @@ package router
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
@@ -31,3 +33,15 @@ func (c *Context) JSON(status int, data interface{}) {
|
||||
c.Out.Write(body)
|
||||
c.Out.Write([]byte("\n"))
|
||||
}
|
||||
|
||||
func (c *Context) VarInt64(key string) (int64, error) {
|
||||
if val, ok := c.Vars[key]; ok {
|
||||
return strconv.ParseInt(val, 10, 64)
|
||||
}
|
||||
return 0, fmt.Errorf("no such var: %s", key)
|
||||
}
|
||||
|
||||
func (c *Context) QueryInt64(key string) (int64, error) {
|
||||
query := c.Req.URL.Query()
|
||||
return strconv.ParseInt(query.Get("page"), 10, 64)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user