1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/image/image.go

47 lines
1.3 KiB
Go
Raw Normal View History

package image
import (
"encoding/json"
"fmt"
"regexp"
"time"
"github.com/docker/docker/runconfig"
)
var validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
type Image struct {
ID string `json:"id"`
Parent string `json:"parent,omitempty"`
Comment string `json:"comment,omitempty"`
Created time.Time `json:"created"`
Container string `json:"container,omitempty"`
ContainerConfig runconfig.Config `json:"container_config,omitempty"`
DockerVersion string `json:"docker_version,omitempty"`
Author string `json:"author,omitempty"`
Config *runconfig.Config `json:"config,omitempty"`
Architecture string `json:"architecture,omitempty"`
OS string `json:"os,omitempty"`
2013-05-13 09:10:26 -04:00
Size int64
}
2013-05-14 21:41:39 -04:00
// Build an Image object from raw json data
2013-06-04 14:00:22 -04:00
func NewImgJSON(src []byte) (*Image, error) {
2013-05-14 21:41:39 -04:00
ret := &Image{}
// FIXME: Is there a cleaner way to "purify" the input json?
if err := json.Unmarshal(src, ret); err != nil {
return nil, err
}
return ret, nil
}
// Check wheather id is a valid image ID or not
func ValidateID(id string) error {
if ok := validHex.MatchString(id); !ok {
return fmt.Errorf("image ID '%s' is invalid", id)
}
return nil
}