mirror of https://github.com/docker/cli.git
Refactor all pre-compiled regexp to package level vars
Addresses #8057 Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
This commit is contained in:
parent
cc0954586a
commit
8b27eee0f0
11
opts/opts.go
11
opts/opts.go
|
@ -14,6 +14,11 @@ import (
|
|||
"github.com/docker/docker/pkg/parsers"
|
||||
)
|
||||
|
||||
var (
|
||||
alphaRegexp = regexp.MustCompile(`[a-zA-Z]`)
|
||||
domainRegexp = regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`)
|
||||
)
|
||||
|
||||
func ListVar(values *[]string, names []string, usage string) {
|
||||
flag.Var(newListOptsRef(values, nil), names, usage)
|
||||
}
|
||||
|
@ -184,12 +189,10 @@ func ValidateDnsSearch(val string) (string, error) {
|
|||
}
|
||||
|
||||
func validateDomain(val string) (string, error) {
|
||||
alpha := regexp.MustCompile(`[a-zA-Z]`)
|
||||
if alpha.FindString(val) == "" {
|
||||
if alphaRegexp.FindString(val) == "" {
|
||||
return "", fmt.Errorf("%s is not a valid domain", val)
|
||||
}
|
||||
re := regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`)
|
||||
ns := re.FindSubmatch([]byte(val))
|
||||
ns := domainRegexp.FindSubmatch([]byte(val))
|
||||
if len(ns) > 0 {
|
||||
return string(ns[1]), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue