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


Golang Image.HasTarsum方法代码示例

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


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

示例1: HeadBlobsV2Handler

func HeadBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	digest := ctx.Params(":digest")
	tarsum := strings.Split(digest, ":")[1]

	i := new(models.Image)
	if has, _ := i.HasTarsum(tarsum); has == false {
		log.Info("[REGISTRY API V2] Tarsum not found: %v", tarsum)

		result, _ := json.Marshal(map[string]string{"message": "Tarsum not found"})
		return http.StatusNotFound, result
	}

	ctx.Resp.Header().Set("Content-Type", "application/x-gzip")
	ctx.Resp.Header().Set("Docker-Content-Digest", digest)
	ctx.Resp.Header().Set("Content-Length", fmt.Sprint(i.Size))

	result, _ := json.Marshal(map[string]string{})
	return http.StatusOK, result
}
开发者ID:haoyuist,项目名称:dockyard,代码行数:19,代码来源:blob.go

示例2: GetBlobsV2Handler

func GetBlobsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	digest := ctx.Params(":digest")

	tarsum := strings.Split(digest, ":")[1]

	i := new(models.Image)
	has, _ := i.HasTarsum(tarsum)
	if has == false {
		log.Error("[REGISTRY API V2] Digest not found: %v", tarsum)

		result, _ := json.Marshal(map[string]string{"message": "Digest not found"})
		return http.StatusNotFound, result
	}

	layerfile := i.Path
	if _, err := os.Stat(layerfile); err != nil {
		log.Error("[REGISTRY API V2] File path is invalid: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "File path is invalid"})
		return http.StatusBadRequest, result
	}

	file, err := ioutil.ReadFile(layerfile)
	if err != nil {
		log.Error("[REGISTRY API V2] Read file failed: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Read file failed"})
		return http.StatusBadRequest, result
	}

	ctx.Resp.Header().Set("Content-Type", "application/x-gzip")
	ctx.Resp.Header().Set("Docker-Content-Digest", digest)
	ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(file)))

	return http.StatusOK, file
}
开发者ID:haoyuist,项目名称:dockyard,代码行数:36,代码来源:blob.go

示例3: Handler

func (n *notification) Handler(ctx *macaron.Context) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	actor := ActorRecord{Name: namespace}
	repo := fmt.Sprintf("%v/%v", namespace, repository)

	switch ctx.Req.Method {
	case "HEAD":
		digest := ctx.Params(":digest")
		tarsum := strings.Split(digest, ":")[1]

		i := new(models.Image)
		if has, _ := i.HasTarsum(tarsum); has == false {
			return
		}

		desc := Descriptor{
			MediaType: DefaultMedisType,
			Size:      i.Size,
			Digest:    digest,
		}

		req := newReqRecord(utils.EncodeBasicAuth(namespace, "headblobsv2"), ctx.Req.Request)
		requrl, err := module.NewURLBuilderFromRequest(ctx.Req.Request).BuildBlobURL(repo, desc.Digest)
		if err != nil {
			fmt.Errorf("[REGISTRY API V2] Head blobs and get request URL failed, error:: %v", err.Error())
		}

		b := newBridge(requrl, actor, req, notice)
		Err := b.createBlobEventAndWrite(EventActionPull, repo, desc)
		if Err.Err != nil {
			ctx.Resp.WriteHeader(http.StatusForbidden)
			return
		} else if Err.StatusCode >= 300 {
			ctx.Resp.WriteHeader(Err.StatusCode)
			return
		}

	case "GET":
		if flag := utils.Compare(ctx.Req.RequestURI, "/v2/"); flag == 0 {
			return
		}

		if flag := strings.Contains(ctx.Req.RequestURI, "/blobs/"); flag == true {
			digest := ctx.Params(":digest")
			tarsum := strings.Split(digest, ":")[1]

			i := new(models.Image)
			if has, _ := i.HasTarsum(tarsum); has == false {
				return
			}

			desc := Descriptor{
				MediaType: BlobMediaType,
				Size:      i.Size,
				Digest:    digest,
			}

			req := newReqRecord(utils.EncodeBasicAuth(namespace, "getblobsv2"), ctx.Req.Request)
			requrl, err := module.NewURLBuilderFromRequest(ctx.Req.Request).BuildBlobURL(repo, desc.Digest)
			if err != nil {
				fmt.Errorf("[REGISTRY API V2] Get blobs and get request URL failed, error:: %v", err.Error())
			}

			b := newBridge(requrl, actor, req, notice)
			Err := b.createBlobEventAndWrite(EventActionPull, repo, desc)
			if Err.Err != nil {
				ctx.Resp.WriteHeader(http.StatusForbidden)
				return
			} else if Err.StatusCode >= 300 {
				ctx.Resp.WriteHeader(Err.StatusCode)
				return
			}
			return
		}

		if flag := strings.Contains(ctx.Req.RequestURI, "/manifests/"); flag == true {
			t := new(models.Tag)
			if err := t.Get(namespace, repository, ctx.Params(":tag")); err != nil {
				return
			}

			digest, err := utils.DigestManifest([]byte(t.Manifest))
			if err != nil {
				fmt.Errorf("[REGISTRY API V2] Get manifest digest failed: %v", err.Error())
				return
			}

			var sm SignedManifest
			if err := json.Unmarshal([]byte(t.Manifest), &sm); err != nil {
				fmt.Errorf("Unmarshal manifest error")
			}

			sm.Raw = make([]byte, len(t.Manifest), len(t.Manifest))
			copy(sm.Raw, []byte(t.Manifest))

			req := newReqRecord(utils.EncodeBasicAuth(namespace, "getmanifestv2"), ctx.Req.Request)
			requrl, err := module.NewURLBuilderFromRequest(ctx.Req.Request).BuildManifestURL(sm.Name, digest)
			if err != nil {
				fmt.Errorf("[REGISTRY API V2] Get manifest and get request URL failed, error:: %v", err.Error())
//.........这里部分代码省略.........
开发者ID:m20082008m,项目名称:dockyard,代码行数:101,代码来源:noticehandler.go


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