parseKeyPatterns converts a JSON array of key pattern objects to []KeyPattern.
(arr []any)
| 445 | |
| 446 | // parseKeyPatterns converts a JSON array of key pattern objects to []KeyPattern. |
| 447 | func parseKeyPatterns(arr []any) []KeyPattern { |
| 448 | var patterns []KeyPattern |
| 449 | for _, item := range arr { |
| 450 | getValue, ok := asStringAnyMap(item) |
| 451 | if !ok { |
| 452 | continue |
| 453 | } |
| 454 | |
| 455 | kp := KeyPattern{ |
| 456 | Target: "service", |
| 457 | Pattern: "default", |
| 458 | SkipLeadingPath: []string{"src/"}, |
| 459 | } |
| 460 | |
| 461 | if v, exists := getValue("target"); exists { |
| 462 | if s, ok := v.(string); ok { |
| 463 | kp.Target = s |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | if v, exists := getValue("pattern"); exists { |
| 468 | if s, ok := v.(string); ok { |
| 469 | kp.Pattern = s |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if v, exists := getValue("skipLeadingPath"); exists { |
| 474 | if arr, ok := v.([]any); ok { |
| 475 | paths := make([]string, 0, len(arr)) |
| 476 | for _, p := range arr { |
| 477 | if s, ok := p.(string); ok { |
| 478 | paths = append(paths, s) |
| 479 | } |
| 480 | } |
| 481 | kp.SkipLeadingPath = paths |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | patterns = append(patterns, kp) |
| 486 | } |
| 487 | return patterns |
| 488 | } |
no outgoing calls
no test coverage detected