• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang models.Image类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/containerops/wharf/models.Image的典型用法代码示例。如果您正苦于以下问题:Golang Image类的具体用法?Golang Image怎么用?Golang Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Image类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetImageLayer

func (this *ImageAPIV1Controller) GetImageLayer() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	if has, _, err := image.Has(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image Layer file Error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read Image None", nil)
		return
	}

	layerfile := image.Path

	if _, err := os.Stat(layerfile); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image file state error", nil)
		return
	}

	file, err := ioutil.ReadFile(layerfile)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image file error", nil)
		return
	}

	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Type", "application/octet-stream")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Transfer-Encoding", "binary")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Length", string(int64(len(file))))
	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body(file)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:33,代码来源:imageapiv1.go


示例2: GetBlobs

func (this *BlobAPIV2Controller) GetBlobs() {
	image := new(models.Image)
	digest := strings.Split(this.Ctx.Input.Param(":digest"), ":")[1]

	if has, _, _ := image.HasTarsum(digest); has == false {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeUnauthorized]}})
		return
	}

	layerfile := image.Path

	if _, err := os.Stat(layerfile); err != nil {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeBlobUnknown]}})
		return
	}

	file, err := ioutil.ReadFile(layerfile)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeBlobUnknown]}})
		return
	}

	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Type", "application/octet-stream")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Transfer-Encoding", "binary")
	this.Ctx.Output.Context.ResponseWriter.Header().Set("Content-Length", string(int64(len(file))))
	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body(file)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:29,代码来源:blobapiv2.go


示例3: HeadDigest

func (this *BlobAPIV2Controller) HeadDigest() {
	image := new(models.Image)
	digest := strings.Split(this.Ctx.Input.Param(":digest"), ":")[1]

	if has, _, _ := image.HasTarsum(digest); has == false {
		this.JSONOut(http.StatusNotFound, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeUnauthorized]}})
		return
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.ServeJson()
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:13,代码来源:blobapiv2.go


示例4: GetImageAncestry

func (this *ImageAPIV1Controller) GetImageAncestry() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	if has, _, err := image.Has(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read Image Ancestry Error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read Image None", nil)
		return
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(image.Ancestry))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:17,代码来源:imageapiv1.go


示例5: PutChecksum

func (this *ImageAPIV1Controller) PutChecksum() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	checksum := strings.Split(this.Ctx.Input.Header("X-Docker-Checksum"), ":")[1]
	payload := strings.Split(this.Ctx.Input.Header("X-Docker-Checksum-Payload"), ":")[1]

	if err := image.PutChecksum(imageId, checksum, true, payload); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Checksum & Payload Error", nil)
		return
	}

	if err := image.PutAncestry(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Ancestry Error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	image.Log(models.ACTION_PUT_IMAGES_CHECKSUM, models.LEVELINFORMATIONAL, models.TYPE_APIV1, image.Id, memo)

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:25,代码来源:imageapiv1.go


示例6: PutImageJSON

func (this *ImageAPIV1Controller) PutImageJSON() {
	imageId := this.Ctx.Input.Param(":image_id")

	image := new(models.Image)

	j := string(this.Ctx.Input.CopyBody())

	if err := image.PutJSON(imageId, j, models.APIVERSION_V1); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image JSON Error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	image.Log(models.ACTION_PUT_IMAGES_JSON, models.LEVELINFORMATIONAL, models.TYPE_APIV1, image.Id, memo)

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:19,代码来源:imageapiv1.go


示例7: PutImageLayer

func (this *ImageAPIV1Controller) PutImageLayer() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	basePath := beego.AppConfig.String("docker::BasePath")
	imagePath := fmt.Sprintf("%v/images/%v", basePath, imageId)
	layerfile := fmt.Sprintf("%v/images/%v/layer", basePath, imageId)

	if !utils.IsDirExists(imagePath) {
		os.MkdirAll(imagePath, os.ModePerm)
	}

	if _, err := os.Stat(layerfile); err == nil {
		os.Remove(layerfile)
	}

	data, _ := ioutil.ReadAll(this.Ctx.Request.Body)

	if err := ioutil.WriteFile(layerfile, data, 0777); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Layer File Error", nil)
		return
	}

	if err := image.PutLayer(imageId, layerfile, true, int64(len(data))); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Layer File Data Error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	image.Log(models.ACTION_PUT_IMAGES_LAYER, models.LEVELINFORMATIONAL, models.TYPE_APIV1, image.Id, memo)

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:36,代码来源:imageapiv1.go


示例8: GetImageJSON

func (this *ImageAPIV1Controller) GetImageJSON() {
	imageId := string(this.Ctx.Input.Param(":image_id"))
	image := new(models.Image)

	var json []byte
	var checksum []byte
	var err error

	if json, err = image.GetJSON(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Search Image JSON Error", nil)
		return
	}

	if checksum, err = image.GetChecksum(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Search Image Checksum Error", nil)
		return
	} else {
		this.Ctx.Output.Context.ResponseWriter.Header().Set("X-Docker-Checksum", string(checksum))
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body(json)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:24,代码来源:imageapiv1.go


示例9: manifestsConvertV1

func manifestsConvertV1(data []byte) error {
	var manifest map[string]interface{}
	if err := json.Unmarshal(data, &manifest); err != nil {
		return err
	}

	tag := manifest["tag"]
	namespace, repository := strings.Split(manifest["name"].(string), "/")[0], strings.Split(manifest["name"].(string), "/")[1]

	for k := len(manifest["history"].([]interface{})) - 1; k >= 0; k-- {
		v := manifest["history"].([]interface{})[k]
		compatibility := v.(map[string]interface{})["v1Compatibility"].(string)

		var image map[string]interface{}
		if err := json.Unmarshal([]byte(compatibility), &image); err != nil {
			return err
		}

		i := map[string]string{}
		r := new(models.Repository)

		if k == 0 {
			i["Tag"] = tag.(string)
		}
		i["id"] = image["id"].(string)

		//Put V1 JSON
		if err := r.PutJSONFromManifests(i, namespace, repository); err != nil {
			return err
		}

		if k == 0 {
			//Put V1 Tag
			if err := r.PutTagFromManifests(image["id"].(string), namespace, repository, tag.(string), string(data)); err != nil {
				return err
			}
		}

		img := new(models.Image)

		tarsum := manifest["fsLayers"].([]interface{})[k].(map[string]interface{})["blobSum"].(string)
		sha256 := strings.Split(tarsum, ":")[1]

		//Put Image Json
		if err := img.PutJSON(image["id"].(string), v.(map[string]interface{})["v1Compatibility"].(string), models.APIVERSION_V2); err != nil {
			return err
		}

		//Put Image Layer
		basePath := beego.AppConfig.String("docker::BasePath")
		layerfile := fmt.Sprintf("%v/uuid/%v/layer", basePath, sha256)

		if err := img.PutLayer(image["id"].(string), layerfile, true, int64(image["Size"].(float64))); err != nil {
			return err
		}

		//Put Checksum
		if err := img.PutChecksum(image["id"].(string), sha256, true, ""); err != nil {
			return err
		}

		//Put Ancestry
		if err := img.PutAncestry(image["id"].(string)); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:rechen,项目名称:wharf,代码行数:69,代码来源:common.go



注:本文中的github.com/containerops/wharf/models.Image类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang models.Organization类代码示例发布时间:2022-05-23
下一篇:
Golang metadata.Chunkserver类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap