evalWildcard extracts all contents of the given value
(input []reflect.Value, node *WildcardNode)
| 378 | |
| 379 | // evalWildcard extracts all contents of the given value |
| 380 | func (j *JSONPath) evalWildcard(input []reflect.Value, node *WildcardNode) ([]reflect.Value, error) { |
| 381 | results := []reflect.Value{} |
| 382 | for _, value := range input { |
| 383 | value, isNil := template.Indirect(value) |
| 384 | if isNil { |
| 385 | continue |
| 386 | } |
| 387 | |
| 388 | kind := value.Kind() |
| 389 | if kind == reflect.Struct { |
| 390 | for i := 0; i < value.NumField(); i++ { |
| 391 | results = append(results, value.Field(i)) |
| 392 | } |
| 393 | } else if kind == reflect.Map { |
| 394 | for _, key := range value.MapKeys() { |
| 395 | results = append(results, value.MapIndex(key)) |
| 396 | } |
| 397 | } else if kind == reflect.Array || kind == reflect.Slice || kind == reflect.String { |
| 398 | for i := 0; i < value.Len(); i++ { |
| 399 | results = append(results, value.Index(i)) |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | return results, nil |
| 404 | } |
| 405 | |
| 406 | // evalRecursive visits the given value recursively and pushes all of them to result |
| 407 | func (j *JSONPath) evalRecursive(input []reflect.Value, node *RecursiveNode) ([]reflect.Value, error) { |