-
Notifications
You must be signed in to change notification settings - Fork 2
/
limit.go
45 lines (40 loc) · 893 Bytes
/
limit.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
35
36
37
38
39
40
41
42
43
44
45
package rsql
import (
"fmt"
"strconv"
)
func (p *RSQL) parseLimit(values map[string]string, params *Params) error {
val, ok := values[p.LimitTag]
params.Limit = p.DefaultLimit
delete(values, p.LimitTag)
if !ok || len(val) < 1 {
return nil
}
u64, err := strconv.ParseUint(val, 10, 64)
if err != nil {
return err
}
if u64 > uint64(maxUint) {
return fmt.Errorf("rsql: overflow unsigned integer, %d", u64)
}
params.Limit = uint(u64)
return nil
}
func (p *RSQL) parseOffset(values map[string]string, params *Params) error {
val, ok := values[p.PageTag]
delete(values, p.PageTag)
if !ok || len(val) < 1 {
return nil
}
u64, err := strconv.ParseUint(val, 10, 64)
if err != nil {
return err
}
if u64 > uint64(maxUint) {
return fmt.Errorf("rsql: overflow unsigned integer, %d", u64)
}
if u64 > 0 {
params.Offset = uint(u64-1) * (params.Limit)
}
return nil
}