-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
55 lines (42 loc) · 895 Bytes
/
list.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
46
47
48
49
50
51
52
53
54
55
// Content managed by Project Forge, see [projectforge.md] for details.
package types
import (
"fmt"
"admini.dev/admini/app/util"
)
const KeyList = "list"
var _ Type = (*List)(nil)
type List struct {
V *Wrapped `json:"v"`
Size int `json:"size,omitempty"`
}
func (x *List) Key() string {
return KeyList
}
func (x *List) Sortable() bool {
return x.V.Sortable()
}
func (x *List) Scalar() bool {
return true
}
func (x *List) String() string {
return fmt.Sprintf("[]%s", x.V.String())
}
func (x *List) From(v any) any {
switch t := v.(type) {
case string:
lt := util.StringSplitAndTrim(t, ",")
return lt
default:
return invalidInput(x.Key(), t)
}
}
func (x *List) Default(string) any {
return emptyList
}
func NewList(t *Wrapped) *Wrapped {
return Wrap(&List{V: t})
}
func NewListSized(t *Wrapped, size int) *Wrapped {
return Wrap(&List{V: t, Size: size})
}