-
Notifications
You must be signed in to change notification settings - Fork 0
/
paramset.go
39 lines (31 loc) · 854 Bytes
/
paramset.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
// Package filter - Content managed by Project Forge, see [projectforge.md] for details.
package filter
import (
"strings"
"github.com/samber/lo"
"admini.dev/admini/app/util"
)
type ParamSet map[string]*Params
func (s ParamSet) Get(key string, allowed []string, logger util.Logger) *Params {
x, ok := s[key]
if !ok {
return &Params{Key: key}
}
return x.Filtered(allowed, logger).Sanitize(key)
}
func (s ParamSet) Sanitized(key string, logger util.Logger, defaultOrderings ...*Ordering) *Params {
ret := s.Get(key, nil, logger).Sanitize(key, defaultOrderings...)
return ret
}
func (s ParamSet) Specifies(key string) bool {
x, ok := s[key]
if !ok {
return false
}
return !x.IsDefault()
}
func (s ParamSet) String() string {
return strings.Join(lo.Map(lo.Values(s), func(p *Params, _ int) string {
return p.String()
}), ", ")
}