本文整理汇总了Golang中registry/storage.Storage.Put方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.Put方法的具体用法?Golang Storage.Put怎么用?Golang Storage.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类registry/storage.Storage
的用法示例。
在下文中一共展示了Storage.Put方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StoreChecksum
func StoreChecksum(s storage.Storage, imageID string, checksums []string) error {
for _, checksum := range checksums {
parts := strings.Split(checksum, ":")
if len(parts) != 2 {
return errors.New("Invalid checksum format")
}
}
content, err := json.Marshal(checksums)
if err != nil {
return err
}
return s.Put(storage.ImageChecksumPath(imageID), content)
}
示例2: GenerateAncestry
func GenerateAncestry(s storage.Storage, imageID, parentID string) (err error) {
logger.Debug("[GenerateAncestry] imageID=" + imageID + " parentID=" + parentID)
path := storage.ImageAncestryPath(imageID)
if parentID == "" {
return s.Put(path, []byte(`["`+imageID+`"]`))
}
var content []byte
if content, err = s.Get(storage.ImageAncestryPath(parentID)); err != nil {
return err
}
var ancestry []string
if err := json.Unmarshal(content, &ancestry); err != nil {
return err
}
ancestry = append([]string{imageID}, ancestry...)
if content, err = json.Marshal(&ancestry); err != nil {
return err
}
return s.Put(path, content)
}
示例3: UpdateIndexImages
// this function takes both []byte and []map[string]interface{} to shortcut in some cases.
func UpdateIndexImages(s storage.Storage, namespace, repo string, additionalBytes []byte,
additional []map[string]interface{}) error {
path := storage.RepoIndexImagesPath(namespace, repo)
// get previous content
previousData, err := s.Get(path)
if err != nil {
// doesn't yet exist, just put the data
return s.Put(path, additionalBytes)
}
var previous []map[string]interface{}
if err := json.Unmarshal(previousData, &previous); err != nil {
return err
}
if len(previous) == 0 {
// nothing in previous, just put the data
return s.Put(path, additionalBytes)
}
// Merge existing images with the incoming images. if the image ID exists in the existing, check to see if
// the checksum is the same. if it is just continue, if it isn't replace it with the incoming image
newImagesMap := map[string]map[string]interface{}{}
for _, value := range additional {
id, ok := value["id"].(string)
if !ok {
// json was screwed up
return errors.New("Invalid Data")
}
if imageData, ok := newImagesMap[id]; ok {
if _, ok := imageData["checksum"]; ok {
continue
}
}
newImagesMap[id] = value
}
for _, value := range previous {
id, ok := value["id"].(string)
if !ok {
// json was screwed up
return errors.New("Invalid Data")
}
if imageData, ok := newImagesMap[id]; ok {
if _, ok := imageData["checksum"]; ok {
continue
}
}
newImagesMap[id] = value
}
newImagesArr := make([]map[string]interface{}, len(newImagesMap))
i := 0
for _, image := range newImagesMap {
newImagesArr[i] = image
i++
}
data, err := json.Marshal(&newImagesArr)
if err != nil {
return err
}
return s.Put(path, data)
}
示例4: SetImageFilesCache
func SetImageFilesCache(s storage.Storage, imageID string, filesJson []byte) error {
return s.Put(storage.ImageFilesPath(imageID), filesJson)
}
示例5: SetImageDiffCache
func SetImageDiffCache(s storage.Storage, imageID string, diffJson []byte) error {
return s.Put(storage.ImageDiffPath(imageID), diffJson)
}