-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.go
54 lines (40 loc) · 929 Bytes
/
reference.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
// Content managed by Project Forge, see [projectforge.md] for details.
package types
import (
"strings"
"golang.org/x/exp/slices"
"admini.dev/admini/app/util"
)
const KeyReference = "reference"
type Reference struct {
Pkg util.Pkg `json:"pkg,omitempty"`
K string `json:"k"`
}
func (x *Reference) Key() string {
return KeyReference
}
func (x *Reference) Sortable() bool {
return true
}
func (x *Reference) Scalar() bool {
return false
}
func (x *Reference) String() string {
return "ref:" + strings.Join(x.Path(), ".")
}
func (x *Reference) From(v any) any {
return invalidInput(x.Key(), v)
}
func (x *Reference) Path() util.Pkg {
ret := slices.Clone(x.Pkg)
return append(ret, x.K)
}
func (x *Reference) Default(string) any {
return ""
}
func NewReference() *Wrapped {
return Wrap(&Reference{})
}
func NewReferenceArgs(pkg util.Pkg, k string) *Wrapped {
return Wrap(&Reference{Pkg: pkg, K: k})
}