reference: move exported regexes to separate block
This makes them easier to find between the non-exported ones, and puts them as separate sections in the generated docs. While updating, also extended documentation for some to be more descriptive. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
a4cec8ca82
commit
02e88c0f15
1 changed files with 33 additions and 31 deletions
|
@ -5,6 +5,39 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DigestRegexp matches well-formed digests, including algorithm (e.g. "sha256:<encoded>").
|
||||||
|
var DigestRegexp = regexp.MustCompile(digestPat)
|
||||||
|
|
||||||
|
// DomainRegexp matches hostname or IP-addresses, optionally including a port
|
||||||
|
// number. It defines the structure of potential domain components that may be
|
||||||
|
// part of image names. This is purposely a subset of what is allowed by DNS to
|
||||||
|
// ensure backwards compatibility with Docker image names. It may be a subset of
|
||||||
|
// DNS domain name, an IPv4 address in decimal format, or an IPv6 address between
|
||||||
|
// square brackets (excluding zone identifiers as defined by [RFC 6874] or special
|
||||||
|
// addresses such as IPv4-Mapped).
|
||||||
|
//
|
||||||
|
// [RFC 6874]: https://www.rfc-editor.org/rfc/rfc6874.
|
||||||
|
var DomainRegexp = regexp.MustCompile(domainAndPort)
|
||||||
|
|
||||||
|
// IdentifierRegexp is the format for string identifier used as a
|
||||||
|
// content addressable identifier using sha256. These identifiers
|
||||||
|
// are like digests without the algorithm, since sha256 is used.
|
||||||
|
var IdentifierRegexp = regexp.MustCompile(identifier)
|
||||||
|
|
||||||
|
// NameRegexp is the format for the name component of references, including
|
||||||
|
// an optional domain and port, but without tag or digest suffix.
|
||||||
|
var NameRegexp = regexp.MustCompile(namePat)
|
||||||
|
|
||||||
|
// ReferenceRegexp is the full supported format of a reference. The regexp
|
||||||
|
// is anchored and has capturing groups for name, tag, and digest
|
||||||
|
// components.
|
||||||
|
var ReferenceRegexp = regexp.MustCompile(referencePat)
|
||||||
|
|
||||||
|
// TagRegexp matches valid tag names. From [docker/docker:graph/tags.go].
|
||||||
|
//
|
||||||
|
// [docker/docker:graph/tags.go]: https://github.com/moby/moby/blob/v1.6.0/graph/tags.go#L26-L28
|
||||||
|
var TagRegexp = regexp.MustCompile(tag)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// alphanumeric defines the alphanumeric atom, typically a
|
// alphanumeric defines the alphanumeric atom, typically a
|
||||||
// component of names. This only allows lower case characters and digits.
|
// component of names. This only allows lower case characters and digits.
|
||||||
|
@ -76,27 +109,10 @@ var (
|
||||||
// compatibility with Docker image names.
|
// compatibility with Docker image names.
|
||||||
domainAndPort = host + optionalPort
|
domainAndPort = host + optionalPort
|
||||||
|
|
||||||
// DomainRegexp matches hostname or IP-addresses, optionally including a port
|
|
||||||
// number. It defines the structure of potential domain components that may be
|
|
||||||
// part of image names. This is purposely a subset of what is allowed by DNS to
|
|
||||||
// ensure backwards compatibility with Docker image names. It may be a subset of
|
|
||||||
// DNS domain name, an IPv4 address in decimal format, or an IPv6 address between
|
|
||||||
// square brackets (excluding zone identifiers as defined by [rfc6874] or special
|
|
||||||
// addresses such as IPv4-Mapped).
|
|
||||||
//
|
|
||||||
// [rfc6874]: https://www.rfc-editor.org/rfc/rfc6874.
|
|
||||||
DomainRegexp = regexp.MustCompile(domainAndPort)
|
|
||||||
|
|
||||||
// TagRegexp matches valid tag names. From docker/docker:graph/tags.go.
|
|
||||||
TagRegexp = regexp.MustCompile(tag)
|
|
||||||
|
|
||||||
// anchoredTagRegexp matches valid tag names, anchored at the start and
|
// anchoredTagRegexp matches valid tag names, anchored at the start and
|
||||||
// end of the matched string.
|
// end of the matched string.
|
||||||
anchoredTagRegexp = regexp.MustCompile(anchored(tag))
|
anchoredTagRegexp = regexp.MustCompile(anchored(tag))
|
||||||
|
|
||||||
// DigestRegexp matches well-formed digests, including algorithm (e.g. "sha256:<encoded>").
|
|
||||||
DigestRegexp = regexp.MustCompile(digestPat)
|
|
||||||
|
|
||||||
// anchoredDigestRegexp matches valid digests, anchored at the start and
|
// anchoredDigestRegexp matches valid digests, anchored at the start and
|
||||||
// end of the matched string.
|
// end of the matched string.
|
||||||
anchoredDigestRegexp = regexp.MustCompile(anchored(digestPat))
|
anchoredDigestRegexp = regexp.MustCompile(anchored(digestPat))
|
||||||
|
@ -113,26 +129,12 @@ var (
|
||||||
remoteName = pathComponent + anyTimes(`/`+pathComponent)
|
remoteName = pathComponent + anyTimes(`/`+pathComponent)
|
||||||
namePat = optional(domainAndPort+`/`) + remoteName
|
namePat = optional(domainAndPort+`/`) + remoteName
|
||||||
|
|
||||||
// NameRegexp is the format for the name component of references, including
|
|
||||||
// an optional domain and port, but without tag or digest suffix.
|
|
||||||
NameRegexp = regexp.MustCompile(namePat)
|
|
||||||
|
|
||||||
// anchoredNameRegexp is used to parse a name value, capturing the
|
// anchoredNameRegexp is used to parse a name value, capturing the
|
||||||
// domain and trailing components.
|
// domain and trailing components.
|
||||||
anchoredNameRegexp = regexp.MustCompile(anchored(optional(capture(domainAndPort), `/`), capture(remoteName)))
|
anchoredNameRegexp = regexp.MustCompile(anchored(optional(capture(domainAndPort), `/`), capture(remoteName)))
|
||||||
|
|
||||||
referencePat = anchored(capture(namePat), optional(`:`, capture(tag)), optional(`@`, capture(digestPat)))
|
referencePat = anchored(capture(namePat), optional(`:`, capture(tag)), optional(`@`, capture(digestPat)))
|
||||||
|
|
||||||
// ReferenceRegexp is the full supported format of a reference. The regexp
|
|
||||||
// is anchored and has capturing groups for name, tag, and digest
|
|
||||||
// components.
|
|
||||||
ReferenceRegexp = regexp.MustCompile(referencePat)
|
|
||||||
|
|
||||||
// IdentifierRegexp is the format for string identifier used as a
|
|
||||||
// content addressable identifier using sha256. These identifiers
|
|
||||||
// are like digests without the algorithm, since sha256 is used.
|
|
||||||
IdentifierRegexp = regexp.MustCompile(identifier)
|
|
||||||
|
|
||||||
// anchoredIdentifierRegexp is used to check or match an
|
// anchoredIdentifierRegexp is used to check or match an
|
||||||
// identifier value, anchored at start and end of string.
|
// identifier value, anchored at start and end of string.
|
||||||
anchoredIdentifierRegexp = regexp.MustCompile(anchored(identifier))
|
anchoredIdentifierRegexp = regexp.MustCompile(anchored(identifier))
|
||||||
|
|
Loading…
Reference in a new issue