Debian Codegraph @

model/value.go

raw symbols SCIP
1 package modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/"
5 "reflectscip-go gomod github.com/golang/go/src go1.25 reflect/"
6 "slicesscip-go gomod github.com/golang/go/src go1.25 slices/"
7 "stringsscip-go gomod github.com/golang/go/src go1.25 strings/"
8 )
9
10 type Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# string
11
12 func (t Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type#) Stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type#String().() string {
13 return string(t)
14 }
15
16 const (
17 TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "string"
18 TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "int"
19 TypeFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeFloat. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "float"
20 TypeBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeBool. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "bool"
21 TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "map"
22 TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "array"
23 TypeUnknownscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeUnknown. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "unknown"
24 TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull. Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# = "null"
25 )
26
27 // KeyValue represents a key value pair.
28 type KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue# struct {
29 Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key. string
30 Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value. *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#
31 }
32
33 // Values represents a list of values.
34 type Valuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Values# []*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#
35
36 // ToSliceValue converts a list of values to a slice value.
37 func (v Valuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Values#) ToSliceValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Values#ToSliceValue().() (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
38 slice := NewSliceValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewSliceValue().()
39 for _, val := range v {
40 if err := slice.Appendscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Append().(val); err != nil {
41 return nil, err
42 }
43 }
44 return slice, nil
45 }
46
47 // Value represents a value.
48 type Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value# struct {
49 valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value. reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25 reflect/Value#
50 Metadatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Metadata. map[string]any
51
52 setFnscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#setFn. func(*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error
53 }
54
55 // String returns the value as a formatted string, along with type info.
56 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#String().() string {
57 return v.stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#string().(0)
58 }
59
60 func indentStrscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/indentStr().(indent int) string {
61 return stringsscip-go gomod github.com/golang/go/src go1.25 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25 strings/Repeat().(" ", indent)
62 }
63
64 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#string().(indent int) string {
65 switch v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() {
66 case TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString.:
67 val, err := v.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().()
68 if err != nil {
69 panic(err)
70 }
71 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("string{%s}", val)
72 case TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt.:
73 val, err := v.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
74 if err != nil {
75 panic(err)
76 }
77 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("int{%d}", val)
78 case TypeFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeFloat.:
79 val, err := v.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().()
80 if err != nil {
81 panic(err)
82 }
83 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("float(%g)", val)
84 case TypeBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeBool.:
85 val, err := v.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().()
86 if err != nil {
87 panic(err)
88 }
89 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("bool{%t}", val)
90 case TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.:
91 res := "{\n"
92 if err := v.RangeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#RangeMap().(func(k string, v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error {
93 res += fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("%s%s: %s,\n", indentStrscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/indentStr().(indent+1), k, v.stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#string().(indent+1))
94 return nil
95 }); err != nil {
96 panic(err)
97 }
98 return res + indentStrscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/indentStr().(indent) + "}"
99 case TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice.:
100 md := ""
101 if v.IsSpreadscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsSpread().() {
102 md = "spread, "
103 }
104 if v.IsBranchscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsBranch().() {
105 md += "branch, "
106 }
107 res := fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("array[%s]{\n", stringsscip-go gomod github.com/golang/go/src go1.25 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.25 strings/TrimSuffix().(md, ", "))
108 if err := v.RangeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#RangeSlice().(func(k int, v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error {
109 res += fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("%s%d: %s,\n", indentStrscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/indentStr().(indent+1), k, v.stringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#string().(indent+1))
110 return nil
111 }); err != nil {
112 panic(err)
113 }
114 return res + indentStrscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/indentStr().(indent) + "}"
115 case TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull.:
116 return indentStrscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/indentStr().(indent) + "null"
117 default:
118 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("unknown[%s]", v.Interfacescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Interface().())
119 }
120 }
121
122 // NewValue creates a new value.
123 func NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(v any) *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value# {
124 switch val := v.(type) {
125 case *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#:
126 return NewNestedValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewNestedValue().(val)
127 case reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25 reflect/Value#:
128 return &Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#{
129 valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.: val,
130 Metadatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Metadata.: nil,
131 }
132 case nil:
133 return NewNullValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewNullValue().()
134 default:
135 res := newPtrscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/newPtr().()
136 if v != nil {
137 res.Elemscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Elem().().Setscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25 reflect/ValueOf().(v))
138 }
139 return &Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#{
140 valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.: res,
141 Metadatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Metadata.: nil,
142 }
143 }
144 }
145
146 // NewNestedValue creates a new nested value.
147 func NewNestedValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewNestedValue().(v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value# {
148 return &Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#{
149 valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.: reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25 reflect/ValueOf().(v),
150 Metadatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Metadata.: nil,
151 }
152 }
153
154 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) isDaselValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDaselValue().() bool {
155 cur := v.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.
156 for cur.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Interface. && !cur.IsNilscip-go gomod github.com/golang/go/src go1.25 reflect/Value#IsNil().() {
157 cur = cur.Elemscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Elem().()
158 }
159 return cur.Typescip-go gomod github.com/golang/go/src go1.25 reflect/Value#Type().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.25 reflect/TypeFor().[*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#]()
160 }
161
162 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) daselValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#daselValue().() (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
163 if v.isDaselValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDaselValue().() {
164 m, err := v.UnpackUntilTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilType().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.25 reflect/TypeFor().[*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#]())
165 if err != nil {
166 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error getting dasel value: %w", err)
167 }
168 return m.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Value#Interface().().(*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#), nil
169 }
170 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("value is not a dasel value")
171 }
172
173 // Interface returns the value as an interface.
174 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Interfacescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Interface().() any {
175 if v.IsNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsNull().() {
176 return nil
177 }
178 return v.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Value#Interface().()
179 }
180
181 // Kind returns the reflect kind of the value.
182 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Kindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Kind().() reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Kind# {
183 return v.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().()
184 }
185
186 // UnpackKinds unpacks the reflect value until it no longer matches the given kinds.
187 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) UnpackKindsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackKinds().(kinds ...reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Kind#) *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value# {
188 val := v
189 for val.isDaselValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDaselValue().() {
190 var err error
191 val, err = val.daselValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#daselValue().()
192 if err != nil {
193 panic(err)
194 }
195 }
196 res := val.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.
197 for {
198 if !slicesscip-go gomod github.com/golang/go/src go1.25 slices/.Containsscip-go gomod github.com/golang/go/src go1.25 slices/Contains().(kinds, res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().()) || res.IsNilscip-go gomod github.com/golang/go/src go1.25 reflect/Value#IsNil().() {
199 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(res)
200 }
201 res = res.Elemscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Elem().()
202 }
203 }
204
205 type ErrCouldNotUnpackToTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrCouldNotUnpackToType# struct {
206 Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrCouldNotUnpackToType#Type. reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Typescip-go gomod github.com/golang/go/src go1.25 reflect/Type#
207 }
208
209 func (e ErrCouldNotUnpackToTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrCouldNotUnpackToType#) Errorscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrCouldNotUnpackToType#Error().() string {
210 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25 fmt/Sprintf().("could not unpack to type: %s", e.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrCouldNotUnpackToType#Type.)
211 }
212
213 // UnpackUntilType unpacks the reflect value until it matches the given type.
214 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) UnpackUntilTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilType().(t reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Typescip-go gomod github.com/golang/go/src go1.25 reflect/Type#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
215 res := v.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.
216 var daselValueType = reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.TypeForscip-go gomod github.com/golang/go/src go1.25 reflect/TypeFor().[*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#]()
217 for {
218 if res.Typescip-go gomod github.com/golang/go/src go1.25 reflect/Value#Type().() == t {
219 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(res), nil
220 }
221 if t != daselValueType && res.Typescip-go gomod github.com/golang/go/src go1.25 reflect/Value#Type().() == daselValueType {
222 m, err := v.daselValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#daselValue().()
223 if err != nil {
224 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error getting dasel value: %w", err)
225 }
226 res = m.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.
227 continue
228
229 }
230 if res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Interface. || res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Pointerscip-go gomod github.com/golang/go/src go1.25 reflect/Pointer. && !res.IsNilscip-go gomod github.com/golang/go/src go1.25 reflect/Value#IsNil().() {
231 res = res.Elemscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Elem().()
232 continue
233 }
234 return nil, &ErrCouldNotUnpackToTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrCouldNotUnpackToType#{Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrCouldNotUnpackToType#Type.: t}
235 }
236 }
237
238 // UnpackUntilAddressable unpacks the reflect value until it is addressable.
239 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) UnpackUntilAddressablescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilAddressable().() (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
240 res := v.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.
241 for {
242 if res.CanAddrscip-go gomod github.com/golang/go/src go1.25 reflect/Value#CanAddr().() {
243 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(res), nil
244 }
245 if res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Interface. || res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Pointerscip-go gomod github.com/golang/go/src go1.25 reflect/Pointer. && !res.IsNilscip-go gomod github.com/golang/go/src go1.25 reflect/Value#IsNil().() {
246 res = res.Elemscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Elem().()
247 continue
248 }
249 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("could not unpack addressable value")
250 }
251 }
252
253 // UnpackUntilKind unpacks the reflect value until it matches the given kind.
254 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) UnpackUntilKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilKind().(k reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Kind#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
255 res := v.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.
256 for {
257 if res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == k {
258 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(res), nil
259 }
260 if res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Interface. || res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Pointerscip-go gomod github.com/golang/go/src go1.25 reflect/Pointer. && !res.IsNilscip-go gomod github.com/golang/go/src go1.25 reflect/Value#IsNil().() {
261 res = res.Elemscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Elem().()
262 continue
263 }
264 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("could not unpack to kind: %s", k)
265 }
266 }
267
268 // UnpackUntilKinds unpacks the reflect value until it matches the given kind.
269 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) UnpackUntilKindsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilKinds().(kinds ...reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Kind#) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
270 res := v.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.
271 for {
272 if slicesscip-go gomod github.com/golang/go/src go1.25 slices/.Containsscip-go gomod github.com/golang/go/src go1.25 slices/Contains().(kinds, res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().()) {
273 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(res), nil
274 }
275 if res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Interface. || res.Kindscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Pointerscip-go gomod github.com/golang/go/src go1.25 reflect/Pointer. && !res.IsNilscip-go gomod github.com/golang/go/src go1.25 reflect/Value#IsNil().() {
276 res = res.Elemscip-go gomod github.com/golang/go/src go1.25 reflect/Value#Elem().()
277 continue
278 }
279 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("could not unpack to kinds: %v", kinds)
280 }
281 }
282
283 // Type returns the type of the value.
284 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type# {
285 switch {
286 case v.IsStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsString().():
287 return TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString.
288 case v.IsIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsInt().():
289 return TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt.
290 case v.IsFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsFloat().():
291 return TypeFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeFloat.
292 case v.IsBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsBool().():
293 return TypeBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeBool.
294 case v.IsMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsMap().():
295 return TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.
296 case v.IsSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsSlice().():
297 return TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice.
298 case v.IsNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsNull().():
299 return TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull.
300 default:
301 return TypeUnknownscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeUnknown.
302 }
303 }
304
305 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) IsScalarscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsScalar().() bool {
306 unpacked := v.UnpackKindsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackKinds().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.25 reflect/Interface., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Pointerscip-go gomod github.com/golang/go/src go1.25 reflect/Pointer.)
307 kind := unpacked.Kindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Kind().()
308
309 switch kind {
310 case reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Stringscip-go gomod github.com/golang/go/src go1.25 reflect/String., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Boolscip-go gomod github.com/golang/go/src go1.25 reflect/Bool., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Intscip-go gomod github.com/golang/go/src go1.25 reflect/Int., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Int8scip-go gomod github.com/golang/go/src go1.25 reflect/Int8., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Int16scip-go gomod github.com/golang/go/src go1.25 reflect/Int16.,
311 reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Int32scip-go gomod github.com/golang/go/src go1.25 reflect/Int32., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Int64scip-go gomod github.com/golang/go/src go1.25 reflect/Int64., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Uintscip-go gomod github.com/golang/go/src go1.25 reflect/Uint., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Uint8scip-go gomod github.com/golang/go/src go1.25 reflect/Uint8., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Uint16scip-go gomod github.com/golang/go/src go1.25 reflect/Uint16.,
312 reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Uint32scip-go gomod github.com/golang/go/src go1.25 reflect/Uint32., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Uint64scip-go gomod github.com/golang/go/src go1.25 reflect/Uint64., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Float32scip-go gomod github.com/golang/go/src go1.25 reflect/Float32., reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Float64scip-go gomod github.com/golang/go/src go1.25 reflect/Float64.:
313 return true
314 default:
315 return unpacked.isNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isNull().()
316 }
317 }
318
319 // Len returns the length of the value.
320 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Len().() (int, error) {
321 var l int
322 var err error
323
324 switch {
325 case v.IsSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsSlice().():
326 l, err = v.SliceLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SliceLen().()
327 case v.IsMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsMap().():
328 l, err = v.MapLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapLen().()
329 case v.IsStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsString().():
330 l, err = v.StringLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringLen().()
331 default:
332 err = ErrUnexpectedTypesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedTypes#{
333 Expectedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedTypes#Expected.: []Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type#{TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice., TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap., TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString.},
334 Actualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedTypes#Actual.: v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().(),
335 }
336 }
337
338 if err != nil {
339 return l, err
340 }
341
342 return l, nil
343 }
344
345 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) Copyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Copy().() (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
346 switch v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() {
347 case TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.:
348 return v.MapCopyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapCopy().()
349 default:
350 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("copy not supported for type: %s", v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().())
351 }
352 }