...

Source file src/github.com/distribution/reference/helpers.go

Documentation: github.com/distribution/reference

     1  package reference
     2  
     3  import "path"
     4  
     5  // IsNameOnly returns true if reference only contains a repo name.
     6  func IsNameOnly(ref Named) bool {
     7  	if _, ok := ref.(NamedTagged); ok {
     8  		return false
     9  	}
    10  	if _, ok := ref.(Canonical); ok {
    11  		return false
    12  	}
    13  	return true
    14  }
    15  
    16  // FamiliarName returns the familiar name string
    17  // for the given named, familiarizing if needed.
    18  func FamiliarName(ref Named) string {
    19  	if nn, ok := ref.(normalizedNamed); ok {
    20  		return nn.Familiar().Name()
    21  	}
    22  	return ref.Name()
    23  }
    24  
    25  // FamiliarString returns the familiar string representation
    26  // for the given reference, familiarizing if needed.
    27  func FamiliarString(ref Reference) string {
    28  	if nn, ok := ref.(normalizedNamed); ok {
    29  		return nn.Familiar().String()
    30  	}
    31  	return ref.String()
    32  }
    33  
    34  // FamiliarMatch reports whether ref matches the specified pattern.
    35  // See [path.Match] for supported patterns.
    36  func FamiliarMatch(pattern string, ref Reference) (bool, error) {
    37  	matched, err := path.Match(pattern, FamiliarString(ref))
    38  	if namedRef, isNamed := ref.(Named); isNamed && !matched {
    39  		matched, _ = path.Match(pattern, FamiliarName(namedRef))
    40  	}
    41  	return matched, err
    42  }
    43  

View as plain text