当前位置: 首页>>代码示例>>Golang>>正文


Golang Storage.Put方法代码示例

本文整理汇总了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)
}
开发者ID:hqm,项目名称:go-docker-registry,代码行数:13,代码来源:util.go

示例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)
}
开发者ID:hqm,项目名称:go-docker-registry,代码行数:20,代码来源:util.go

示例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)
}
开发者ID:hqm,项目名称:go-docker-registry,代码行数:59,代码来源:util.go

示例4: SetImageFilesCache

func SetImageFilesCache(s storage.Storage, imageID string, filesJson []byte) error {
	return s.Put(storage.ImageFilesPath(imageID), filesJson)
}
开发者ID:hqm,项目名称:go-docker-registry,代码行数:3,代码来源:util.go

示例5: SetImageDiffCache

func SetImageDiffCache(s storage.Storage, imageID string, diffJson []byte) error {
	return s.Put(storage.ImageDiffPath(imageID), diffJson)
}
开发者ID:hqm,项目名称:go-docker-registry,代码行数:3,代码来源:util.go


注:本文中的registry/storage.Storage.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。