(c context.Context, key gval.Evaluable, r, v interface{})
| 64 | } |
| 65 | |
| 66 | func selectValue(c context.Context, key gval.Evaluable, r, v interface{}) (value interface{}, jkey string, err error) { |
| 67 | c = currentContext(c, v) |
| 68 | switch o := v.(type) { |
| 69 | case []interface{}: |
| 70 | i, err := key.EvalInt(c, r) |
| 71 | if err != nil { |
| 72 | return nil, "", fmt.Errorf("could not select value, invalid key: %s", err) |
| 73 | } |
| 74 | if i < 0 || i >= len(o) { |
| 75 | return nil, "", fmt.Errorf("index %d out of bounds", i) |
| 76 | } |
| 77 | return o[i], strconv.Itoa(i), nil |
| 78 | case map[string]interface{}: |
| 79 | k, err := key.EvalString(c, r) |
| 80 | if err != nil { |
| 81 | return nil, "", fmt.Errorf("could not select value, invalid key: %s", err) |
| 82 | } |
| 83 | |
| 84 | if r, ok := o[k]; ok { |
| 85 | return r, k, nil |
| 86 | } |
| 87 | return nil, "", fmt.Errorf("unknown key %s", k) |
| 88 | |
| 89 | default: |
| 90 | return nil, "", fmt.Errorf("unsupported value type %T for select, expected map[string]interface{} or []interface{}", o) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | //.. |
| 95 | func mapperSelector() ambiguousSelector { |
no test coverage detected
searching dependent graphs…