-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.go
34 lines (30 loc) · 915 Bytes
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package request
import (
BizError "github.com/HDT3213/go-gin-demo/lib/errors"
"github.com/gin-gonic/gin"
"strconv"
)
func GetPage(ctx *gin.Context, defaultStart int32, defaultLength int32) (int32, int32, error) {
var err error
rawStart := ctx.Query("start")
var start int64
if len(rawStart) > 0 {
start, err = strconv.ParseInt(rawStart, 10, 32)
if err != nil {
return -1, -1, BizError.InvalidForm( "invalid start: " + rawStart)
}
} else {
start = int64(defaultStart)
}
rawLength := ctx.Query("length")
var length int64
if len(rawLength) > 0 {
length, err = strconv.ParseInt(rawLength, 10, 32)
if err != nil {
return -1, -1, BizError.InvalidForm( "invalid length: " + rawLength)
}
} else {
length = int64(defaultLength)
}
return int32(start), int32(length), nil
}