adapted from: https://stackoverflow.com/a/28878037 (credit)
(m any, path ...any)
| 274 | |
| 275 | // adapted from: https://stackoverflow.com/a/28878037 (credit) |
| 276 | func get(m any, path ...any) (any, bool) { |
| 277 | for _, p := range path { |
| 278 | switch idx := p.(type) { |
| 279 | case string: |
| 280 | if mm, ok := m.(map[string]any); ok { |
| 281 | if val, found := mm[idx]; found { |
| 282 | m = val |
| 283 | continue |
| 284 | } |
| 285 | } |
| 286 | return nil, false |
| 287 | case int: |
| 288 | if mm, ok := m.([]any); ok { |
| 289 | if len(mm) > idx { |
| 290 | m = mm[idx] |
| 291 | continue |
| 292 | } |
| 293 | } |
| 294 | return nil, false |
| 295 | } |
| 296 | } |
| 297 | return m, true |
| 298 | } |
no outgoing calls