MCPcopy Create free account
hub / github.com/zalando/skipper / parseAnnotationConfig

Function parseAnnotationConfig

config/config.go:1470–1504  ·  view source on GitHub ↗

parseAnnotationConfig parses a slice of strings in the "annotationKey=annotationValue=value" format by calling parseValue function to convert (annotationKey, annotationValue, value) tuple into T. Empty input strings are skipped and duplicate annotationKey-annotationValue pairs are rejected with erro

(kvvs []string, parseValue func(annotationKey, annotationValue, value string) (T, error))

Source from the content-addressed store, hash-verified

1468// by calling parseValue function to convert (annotationKey, annotationValue, value) tuple into T.
1469// Empty input strings are skipped and duplicate annotationKey-annotationValue pairs are rejected with error.
1470func parseAnnotationConfig[T any](kvvs []string, parseValue func(annotationKey, annotationValue, value string) (T, error)) ([]T, error) {
1471 var result []T
1472 seenKVs := make(map[string]struct{})
1473 for _, kvv := range kvvs {
1474 if kvv == "" {
1475 continue
1476 }
1477
1478 annotationKey, rest, found := strings.Cut(kvv, "=")
1479 if !found {
1480 return nil, fmt.Errorf("invalid annotation flag: %q, failed to get annotation key", kvv)
1481 }
1482
1483 annotationValue, value, found := strings.Cut(rest, "=")
1484 if !found {
1485 return nil, fmt.Errorf("invalid annotation flag: %q, failed to get annotation value", kvv)
1486 }
1487
1488 v, err := parseValue(annotationKey, annotationValue, value)
1489 if err != nil {
1490 return nil, fmt.Errorf("invalid annotation flag value: %q, %w", kvv, err)
1491 }
1492
1493 // Reject duplicate annotation key-value pairs
1494 kv := annotationKey + "=" + annotationValue
1495 if _, ok := seenKVs[kv]; ok {
1496 return nil, fmt.Errorf("invalid annotation flag: %q, duplicate annotation key-value %q", kvv, kv)
1497 } else {
1498 seenKVs[kv] = struct{}{}
1499 }
1500
1501 result = append(result, v)
1502 }
1503 return result, nil
1504}

Callers 2

parseAnnotationFiltersFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…