github.com/reds/docker@v1.11.2-rc1/distribution/metadata/v1_id_service.go (about) 1 package metadata 2 3 import ( 4 "github.com/docker/docker/image/v1" 5 "github.com/docker/docker/layer" 6 ) 7 8 // V1IDService maps v1 IDs to layers on disk. 9 type V1IDService struct { 10 store Store 11 } 12 13 // NewV1IDService creates a new V1 ID mapping service. 14 func NewV1IDService(store Store) *V1IDService { 15 return &V1IDService{ 16 store: store, 17 } 18 } 19 20 // namespace returns the namespace used by this service. 21 func (idserv *V1IDService) namespace() string { 22 return "v1id" 23 } 24 25 // Get finds a layer by its V1 ID. 26 func (idserv *V1IDService) Get(v1ID, registry string) (layer.DiffID, error) { 27 if err := v1.ValidateID(v1ID); err != nil { 28 return layer.DiffID(""), err 29 } 30 31 idBytes, err := idserv.store.Get(idserv.namespace(), registry+","+v1ID) 32 if err != nil { 33 return layer.DiffID(""), err 34 } 35 return layer.DiffID(idBytes), nil 36 } 37 38 // Set associates an image with a V1 ID. 39 func (idserv *V1IDService) Set(v1ID, registry string, id layer.DiffID) error { 40 if err := v1.ValidateID(v1ID); err != nil { 41 return err 42 } 43 return idserv.store.Set(idserv.namespace(), registry+","+v1ID, []byte(id)) 44 }