github.com/robertojrojas/docker@v1.9.1/graph/tags/tags.go (about) 1 package tags 2 3 import ( 4 "fmt" 5 6 "github.com/docker/distribution/registry/api/v2" 7 ) 8 9 // DefaultTag defines the default tag used when performing images related actions and no tag string is specified 10 const DefaultTag = "latest" 11 12 // ErrTagInvalidFormat is returned if tag is invalid. 13 type ErrTagInvalidFormat struct { 14 name string 15 } 16 17 func (e ErrTagInvalidFormat) Error() string { 18 return fmt.Sprintf("Illegal tag name (%s): only [A-Za-z0-9_.-] are allowed ('.' and '-' are NOT allowed in the initial), minimum 1, maximum 128 in length", e.name) 19 } 20 21 // ValidateTagName validates the name of a tag. 22 // It returns an error if the given name is an emtpy string. 23 // If name does not match v2.TagNameAnchoredRegexp regexp, it returns ErrTagInvalidFormat 24 func ValidateTagName(name string) error { 25 if name == "" { 26 return fmt.Errorf("tag name can't be empty") 27 } 28 29 if !v2.TagNameAnchoredRegexp.MatchString(name) { 30 return ErrTagInvalidFormat{name} 31 } 32 return nil 33 }