github.com/glycerine/docker@v1.8.2/image/image.go (about) 1 package image 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "regexp" 7 "time" 8 9 "github.com/docker/docker/runconfig" 10 ) 11 12 var validHex = regexp.MustCompile(`^([a-f0-9]{64})$`) 13 14 type Image struct { 15 ID string `json:"id"` 16 Parent string `json:"parent,omitempty"` 17 Comment string `json:"comment,omitempty"` 18 Created time.Time `json:"created"` 19 Container string `json:"container,omitempty"` 20 ContainerConfig runconfig.Config `json:"container_config,omitempty"` 21 DockerVersion string `json:"docker_version,omitempty"` 22 Author string `json:"author,omitempty"` 23 Config *runconfig.Config `json:"config,omitempty"` 24 Architecture string `json:"architecture,omitempty"` 25 OS string `json:"os,omitempty"` 26 Size int64 27 } 28 29 // Build an Image object from raw json data 30 func NewImgJSON(src []byte) (*Image, error) { 31 ret := &Image{} 32 33 // FIXME: Is there a cleaner way to "purify" the input json? 34 if err := json.Unmarshal(src, ret); err != nil { 35 return nil, err 36 } 37 return ret, nil 38 } 39 40 // Check wheather id is a valid image ID or not 41 func ValidateID(id string) error { 42 if ok := validHex.MatchString(id); !ok { 43 return fmt.Errorf("image ID '%s' is invalid", id) 44 } 45 return nil 46 }