MCPcopy Create free account
hub / github.com/bufbuild/buf / getRawPathAndOptions

Function getRawPathAndOptions

private/buf/buffetch/internal/ref_parser.go:416–454  ·  view source on GitHub ↗

getRawPathAndOptions returns the raw path and options from the value provided, the rawPath will be non-empty when returning without error here.

(value string)

Source from the content-addressed store, hash-verified

414// getRawPathAndOptions returns the raw path and options from the value provided,
415// the rawPath will be non-empty when returning without error here.
416func getRawPathAndOptions(value string) (string, map[string]string, error) {
417 value = strings.TrimSpace(value)
418 if value == "" {
419 return "", nil, newValueEmptyError()
420 }
421
422 switch splitValue := strings.Split(value, "#"); len(splitValue) {
423 case 1:
424 return value, nil, nil
425 case 2:
426 path := strings.TrimSpace(splitValue[0])
427 optionsString := strings.TrimSpace(splitValue[1])
428 if path == "" {
429 return "", nil, newValueStartsWithHashtagError(value)
430 }
431 if optionsString == "" {
432 return "", nil, newValueEndsWithHashtagError(value)
433 }
434 options := make(map[string]string)
435 for pair := range strings.SplitSeq(optionsString, ",") {
436 split := strings.Split(pair, "=")
437 if len(split) != 2 {
438 return "", nil, newOptionsInvalidError(optionsString)
439 }
440 key := strings.TrimSpace(split[0])
441 value := strings.TrimSpace(split[1])
442 if key == "" || value == "" {
443 return "", nil, newOptionsInvalidError(optionsString)
444 }
445 if _, ok := options[key]; ok {
446 return "", nil, newOptionsDuplicateKeyError(key)
447 }
448 options[key] = value
449 }
450 return path, options, nil
451 default:
452 return "", nil, newValueMultipleHashtagsError(value)
453 }
454}
455
456func getSingleRef(
457 rawRef *RawRef,

Callers 3

getParsedRefMethod · 0.85
GetInputConfigForRefFunction · 0.85

Calls 6

newValueEmptyErrorFunction · 0.85
newOptionsInvalidErrorFunction · 0.85

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…