-
Notifications
You must be signed in to change notification settings - Fork 43
/
filter.go
44 lines (37 loc) · 950 Bytes
/
filter.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
package models
import "strings"
type ListView struct {
Total int `json:"total"`
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
Items interface{} `json:"items,omitempty"`
}
type Filter struct {
PageNo int `form:"pageNo"`
PageSize int `form:"pageSize"`
Name string `form:"name,omitempty"`
}
type ListOptions struct {
LabelSelector string `form:"selector,omitempty"`
FieldSelector string `form:"fieldSelector,omitempty"`
Limit int64 `form:"limit,omitempty"`
Continue string `form:"continue,omitempty"`
Filter
}
func (f *Filter) GetLimitOffset() int {
if f.PageNo <= 0 {
f.PageNo = 1
}
return (f.PageNo - 1) * f.GetLimitNumber()
}
func (f *Filter) GetLimitNumber() int {
return f.PageSize
}
func (f *Filter) GetFuzzyName() string {
if f.Name == "" {
f.Name = "%"
} else if !strings.Contains(f.Name, "%") {
f.Name = "%" + f.Name + "%"
}
return f.Name
}