-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparams.go
42 lines (34 loc) · 892 Bytes
/
params.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
// Package search - Content managed by Project Forge, see [projectforge.md] for details.
package search
import (
"strings"
"github.com/samber/lo"
"projectforge.dev/projectforge/app/lib/filter"
"projectforge.dev/projectforge/app/util"
)
type Params struct {
Q string `json:"q"`
PS filter.ParamSet `json:"ps,omitempty"`
}
func (p *Params) String() string {
return p.Q
}
func (p *Params) Parts() []string {
return util.StringSplitAndTrim(p.Q, " ")
}
func (p *Params) General() []string {
return lo.Filter(p.Parts(), func(x string, _ int) bool {
return !strings.Contains(x, ":")
})
}
func (p *Params) Keyed() util.ValueMap {
x := lo.Filter(p.Parts(), func(x string, _ int) bool {
return strings.Contains(x, ":")
})
ret := make(util.ValueMap, len(x))
lo.ForEach(x, func(s string, _ int) {
k, v := util.StringSplit(s, ':', true)
ret[k] = v
})
return ret
}