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