MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / getPathInternal

Function getPathInternal

pkg/ijson/ijson.go:183–213  ·  view source on GitHub ↗
(data any, pp pathWithPos)

Source from the content-addressed store, hash-verified

181}
182
183func getPathInternal(data any, pp pathWithPos) (any, error) {
184 if data == nil {
185 return nil, nil
186 }
187 if pp.Index >= len(pp.Path) {
188 return data, nil
189 }
190 pathElemAny := pp.Path[pp.Index]
191 switch pathElem := pathElemAny.(type) {
192 case string:
193 mapVal, ok := data.(map[string]any)
194 if !ok {
195 return nil, nil
196 }
197 return getPathInternal(mapVal[pathElem], pathWithPos{Path: pp.Path, Index: pp.Index + 1})
198 case int:
199 if pathElem < 0 {
200 return nil, MakePathError("negative index", pp.Path, pp.Index)
201 }
202 arrVal, ok := data.([]any)
203 if !ok {
204 return nil, nil
205 }
206 if pathElem >= len(arrVal) {
207 return nil, nil
208 }
209 return getPathInternal(arrVal[pathElem], pathWithPos{Path: pp.Path, Index: pp.Index + 1})
210 default:
211 return nil, MakePathTypeError(pp.Path, pp.Index)
212 }
213}
214
215type CombiningFunc func(curValue any, newValue any, pp pathWithPos, opts SetPathOpts) (any, error)
216

Callers 1

GetPathFunction · 0.85

Calls 2

MakePathErrorFunction · 0.85
MakePathTypeErrorFunction · 0.85

Tested by

no test coverage detected