Debian Codegraph @

model/value_map.go

raw symbols SCIP
1 package modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.25 errors/"
5 "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/"
6 "reflectscip-go gomod github.com/golang/go/src go1.25 reflect/"
7
8 "github.com/tomwright/dasel/v3/model/orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/"
9 )
10
11 // NewMapValue creates a new map value.
12 func NewMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewMapValue().() *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value# {
13 return NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().())
14 }
15
16 // IsMap returns true if the value is a map.
17 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) IsMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IsMap().() bool {
18 return v.isStandardMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isStandardMap().() || v.isDencodingMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDencodingMap().()
19 }
20
21 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) isStandardMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isStandardMap().() bool {
22 return 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.).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/.Mapscip-go gomod github.com/golang/go/src go1.25 reflect/Map.
23 }
24
25 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) isDencodingMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDencodingMap().() bool {
26 return 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.).valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..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().[orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#]()
27 }
28
29 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) dencodingMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#dencodingMapValue().() (*orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#, error) {
30 if v.isDencodingMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDencodingMap().() {
31 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().[*orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#]())
32 if err != nil {
33 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 map: %w", err)
34 }
35 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().().(*orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/.Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#), nil
36 }
37 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 dencoding map")
38 }
39
40 // SetMapKey sets the value at the specified key in the map.
41 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().(key string, value *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error {
42 switch {
43 case v.isDencodingMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDencodingMap().():
44 m, err := v.dencodingMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#dencodingMapValue().()
45 if err != nil {
46 return 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 map: %w", err)
47 }
48 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().(key, value)
49 return nil
50 case v.isStandardMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isStandardMap().():
51 unpacked, err := v.UnpackUntilKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilKind().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Mapscip-go gomod github.com/golang/go/src go1.25 reflect/Map.)
52 if err != nil {
53 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error unpacking value: %w", err)
54 }
55 unpacked.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..SetMapIndexscip-go gomod github.com/golang/go/src go1.25 reflect/Value#SetMapIndex().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25 reflect/ValueOf().(key), value.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.)
56 return nil
57 default:
58 return 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 map")
59 }
60 }
61
62 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) MapCopyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapCopy().() (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
63 res := NewMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewMapValue().()
64 kvs, err := v.MapKeyValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeyValues().()
65 if err != nil {
66 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 map key values: %w", err)
67 }
68 for _, kv := range kvs {
69 if err := res.SetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SetMapKey().(kv.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key., kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value.); err != nil {
70 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 setting map key: %w", err)
71 }
72 }
73 return res, nil
74 }
75
76 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) MapKeyExistsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeyExists().(key string) (bool, error) {
77 _, err := v.GetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetMapKey().(key)
78 if err != nil && !errorsscip-go gomod github.com/golang/go/src go1.25 errors/.Asscip-go gomod github.com/golang/go/src go1.25 errors/As().(err, &MapKeyNotFoundscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/MapKeyNotFound#{}) {
79 return false, err
80 }
81 return err == nil, nil
82 }
83
84 // GetMapKey returns the value at the specified key in the map.
85 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) GetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetMapKey().(key string) (*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
86 switch {
87 case v.isDencodingMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDencodingMap().():
88 m, err := v.dencodingMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#dencodingMapValue().()
89 if err != nil {
90 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 map: %w", err)
91 }
92 val, ok := m.Getscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Get().(key)
93 if !ok {
94 return nil, MapKeyNotFoundscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/MapKeyNotFound#{Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/MapKeyNotFound#Key.: key}
95 }
96 if modelValue, isValue := val.(*Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#); isValue {
97 modelValue.setFnscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#setFn. = func(newValue *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error {
98 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().(key, newValue)
99 return nil
100 }
101 return modelValue, nil
102 }
103 res := NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(val)
104 res.setFnscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#setFn. = func(newValue *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error {
105 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().(key, newValue)
106 return nil
107 }
108 return res, nil
109 case v.isStandardMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isStandardMap().():
110 unpacked, err := v.UnpackUntilKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilKind().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Mapscip-go gomod github.com/golang/go/src go1.25 reflect/Map.)
111 if err != nil {
112 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 unpacking value: %w", err)
113 }
114 i := unpacked.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..MapIndexscip-go gomod github.com/golang/go/src go1.25 reflect/Value#MapIndex().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25 reflect/ValueOf().(key))
115 if !i.IsValidscip-go gomod github.com/golang/go/src go1.25 reflect/Value#IsValid().() {
116 return nil, MapKeyNotFoundscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/MapKeyNotFound#{Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/MapKeyNotFound#Key.: key}
117 }
118 res := NewValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewValue().(i)
119 res.setFnscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#setFn. = func(newValue *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error {
120 mapRv, err := v.UnpackUntilKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilKind().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Mapscip-go gomod github.com/golang/go/src go1.25 reflect/Map.)
121 if err != nil {
122 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error unpacking value: %w", err)
123 }
124 mapRv.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..SetMapIndexscip-go gomod github.com/golang/go/src go1.25 reflect/Value#SetMapIndex().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25 reflect/ValueOf().(key), newValue.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value.)
125 return nil
126 }
127 return res, nil
128 default:
129 return nil, ErrUnexpectedTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#{
130 Expectedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#Expected.: TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.,
131 Actualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#Actual.: v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().(),
132 }
133 }
134 }
135
136 // DeleteMapKey deletes the key from the map.
137 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) DeleteMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#DeleteMapKey().(key string) error {
138 switch {
139 case v.isDencodingMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDencodingMap().():
140 m, err := v.dencodingMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#dencodingMapValue().()
141 if err != nil {
142 return 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 map: %w", err)
143 }
144 m.Deletescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Delete().(key)
145 return nil
146 case v.isStandardMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isStandardMap().():
147 unpacked, err := v.UnpackUntilKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilKind().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Mapscip-go gomod github.com/golang/go/src go1.25 reflect/Map.)
148 if err != nil {
149 return fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error unpacking value: %w", err)
150 }
151 unpacked.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..SetMapIndexscip-go gomod github.com/golang/go/src go1.25 reflect/Value#SetMapIndex().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.25 reflect/ValueOf().(key), reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Valuescip-go gomod github.com/golang/go/src go1.25 reflect/Value#{})
152 return nil
153 default:
154 return ErrUnexpectedTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#{
155 Expectedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#Expected.: TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.,
156 Actualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#Actual.: v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().(),
157 }
158 }
159 }
160
161 // MapKeys returns a list of keys in the map.
162 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) MapKeysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeys().() ([]string, error) {
163 switch {
164 case v.isDencodingMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isDencodingMap().():
165 m, err := v.dencodingMapValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#dencodingMapValue().()
166 if err != nil {
167 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 map: %w", err)
168 }
169 return m.Keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Keys().(), nil
170 case v.isStandardMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#isStandardMap().():
171 unpacked, err := v.UnpackUntilKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#UnpackUntilKind().(reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.Mapscip-go gomod github.com/golang/go/src go1.25 reflect/Map.)
172 if err != nil {
173 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 unpacking value: %w", err)
174 }
175 keys := unpacked.valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#value..MapKeysscip-go gomod github.com/golang/go/src go1.25 reflect/Value#MapKeys().()
176 strKeys := make([]string, len(keys))
177 for i, k := range keys {
178 strKeys[i] = k.Stringscip-go gomod github.com/golang/go/src go1.25 reflect/Value#String().()
179 }
180 return strKeys, nil
181 default:
182 return nil, ErrUnexpectedTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#{
183 Expectedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#Expected.: TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.,
184 Actualscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/ErrUnexpectedType#Actual.: v.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().(),
185 }
186 }
187 }
188
189 // RangeMap iterates over each key in the map and calls the provided function with the key and value.
190 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) RangeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#RangeMap().(f func(string, *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) error) error {
191 keys, err := v.MapKeysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeys().()
192 if err != nil {
193 return 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 map keys: %w", err)
194 }
195
196 for _, k := range keys {
197 va, err := v.GetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetMapKey().(k)
198 if err != nil {
199 return 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 map key: %w", err)
200 }
201 if err := f(k, va); err != nil {
202 return err
203 }
204 }
205
206 return nil
207 }
208
209 // MapKeyValues returns a list of key value pairs in the map.
210 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) MapKeyValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeyValues().() ([]KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#, error) {
211 keys, err := v.MapKeysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeys().()
212 if err != nil {
213 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 map keys: %w", err)
214 }
215
216 kvs := make([]KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#, len(keys))
217
218 for i, k := range keys {
219 va, err := v.GetMapKeyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetMapKey().(k)
220 if err != nil {
221 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 map key: %w", err)
222 }
223 kvs[i] = KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#{
224 Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key.: k,
225 Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value.: va,
226 }
227 }
228
229 return kvs, nil
230 }
231
232 // MapLen returns the length of the slice.
233 func (v *Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) MapLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapLen().() (int, error) {
234 keys, err := v.MapKeysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeys().()
235 if err != nil {
236 return 0, err
237 }
238 return len(keys), nil
239 }