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

Golang models.Tag类代码示例

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

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



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

示例1: GetManifestsV2Handler

func GetManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	t := new(models.Tag)

	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	if err := t.Get(namespace, repository, ctx.Params(":tag")); err != nil {
		log.Error("[REGISTRY API V2] Manifest not found: %v", err.Error())

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

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

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

	ctx.Resp.Header().Set("Content-Type", "application/json; charset=utf-8")
	ctx.Resp.Header().Set("Docker-Content-Digest", digest)
	ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(t.Manifest)))

	return http.StatusOK, []byte(t.Manifest)
}
开发者ID:CodeJuan,项目名称:dockyard,代码行数:26,代码来源:manifests.go


示例2: GetTagsListV2Handler

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

	r := new(models.Repository)
	if has, _, err := r.Has(namespace, repository); err != nil || has == false {
		log.Error("[REGISTRY API V2] Repository not found: %v", repository)

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

	data := map[string]interface{}{}
	tags := []string{}

	data["name"] = fmt.Sprintf("%s/%s", namespace, repository)

	for _, value := range r.Tags {
		t := new(models.Tag)
		if err := t.GetByKey(value); err != nil {
			log.Error("[REGISTRY API V2] Tag not found: %v", err.Error())

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

		tags = append(tags, t.Name)
	}

	data["tags"] = tags

	result, _ := json.Marshal(data)
	return http.StatusOK, result
}
开发者ID:CodeJuan,项目名称:dockyard,代码行数:34,代码来源:manifests.go


示例3: GetTagV1Handler

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

	r := new(models.Repository)
	if exists, err := r.Get(namespace, repository); err != nil {
		log.Error("[REGISTRY API V1] Failed to get repository %v/%v context: %v", namespace, repository, err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Failed to get repository context"})
		return http.StatusBadRequest, result
	} else if exists == false {
		log.Error("[REGISTRY API V1] Not found repository %v/%v", namespace, repository)

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

	tags := map[string]string{}
	tagslist := r.GetTagslist()
	for _, tagname := range tagslist {
		t := new(models.Tag)
		if exists, err := t.Get(namespace, repository, tagname); err != nil || !exists {
			log.Error(fmt.Sprintf("[REGISTRY API V1]  %s/%s %v is not exist", namespace, repository, tagname))

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

		tags[tagname] = t.ImageId
	}

	result, _ := json.Marshal(tags)
	return http.StatusOK, result
}
开发者ID:maquanyi,项目名称:dockyard,代码行数:34,代码来源:repository.go


示例4: GetManifestsV2Handler

func GetManifestsV2Handler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	tag := ctx.Params(":tag")

	t := new(models.Tag)
	if exists, err := t.Get(namespace, repository, tag); err != nil || !exists {
		log.Error("[REGISTRY API V2] Not found manifest: %v", err)

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

	digest, err := signature.DigestManifest([]byte(t.Manifest))
	if err != nil {
		log.Error("[REGISTRY API V2] Failed to get manifest digest: %v", err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Failed to get manifest digest"})
		return http.StatusInternalServerError, result
	}

	contenttype := []string{"", "application/json; charset=utf-8", "application/vnd.docker.distribution.manifest.v2+json"}
	ctx.Resp.Header().Set("Content-Type", contenttype[t.Schema])

	ctx.Resp.Header().Set("Docker-Content-Digest", digest)
	ctx.Resp.Header().Set("Content-Length", fmt.Sprint(len(t.Manifest)))

	return http.StatusOK, []byte(t.Manifest)
}
开发者ID:yanghongkjxy,项目名称:dockyard,代码行数:29,代码来源:manifests.go


示例5: PostCompleteHandler

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

	body, _ := ctx.Req.Body().Bytes()
	if err := module.CheckClientStatus(body); err != nil {
		module.CleanCache(imageId, setting.APIVERSION_ACI)
		log.Error("[ACI API] Failed to push aci: %v", err.Error())

		failmsg := module.FillRespMsg(false, err.Error(), "")
		result, _ := json.Marshal(failmsg)
		return http.StatusInternalServerError, result
	}

	namespace := ctx.Params(":namespace")
	acifile := ctx.Params(":acifile")
	signfile := ctx.Params(":signfile")

	//TODO: only for testing,pubkey will be read and saved via user management module
	pubkeyspath := module.GetPubkeysPath(namespace, repository, setting.APIVERSION_ACI)
	acifilepath := module.GetLayerPath(imageId, acifile, setting.APIVERSION_ACI)
	signfilepath := module.GetSignaturePath(imageId, signfile, setting.APIVERSION_ACI)
	manipath := module.GetManifestPath(imageId, setting.APIVERSION_ACI)
	if err := module.VerifyAciSignature(acifilepath, signfilepath, pubkeyspath); err != nil {
		module.CleanCache(imageId, setting.APIVERSION_ACI)
		log.Error("[ACI API] Failed to verify Aci: %v", err.Error())

		failmsg := module.FillRespMsg(false, "", err.Error())
		result, _ := json.Marshal(failmsg)
		return http.StatusInternalServerError, result
	}

	//If aci image is existent,it should update the db and delete the old image after executed successfully
	var oldimageId = ""
	tag := strings.Trim(acifile, ".aci")
	t := new(models.Tag)
	if exists, err := t.Get(namespace, repository, tag); err == nil && exists {
		oldimageId = t.ImageId
	}

	a := new(models.Aci)
	if err := a.Update(namespace, repository, tag, imageId, manipath, signfilepath, acifilepath); err != nil {
		module.CleanCache(imageId, setting.APIVERSION_ACI)
		log.Error("[ACI API] Failed to update %v/%v: %v", namespace, repository, err.Error())

		failmsg := module.FillRespMsg(false, "", err.Error())
		result, _ := json.Marshal(failmsg)
		return http.StatusInternalServerError, result
	}

	//Delete old aci directory after redis is updated
	if oldimageId != "" {
		module.CleanCache(oldimageId, setting.APIVERSION_ACI)
	}

	successmsg := module.FillRespMsg(true, "", "")
	result, _ := json.Marshal(successmsg)
	return http.StatusOK, result
}
开发者ID:yanghongkjxy,项目名称:dockyard,代码行数:59,代码来源:aci.go


示例6: GetACIHandler

func GetACIHandler(ctx *macaron.Context, log *logs.BeeLogger) (int, []byte) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")
	acifilename := ctx.Params(":acifilename")

	acifile := strings.Trim(acifilename, ".asc")
	tag := strings.Trim(acifile, ".aci")

	t := new(models.Tag)
	if exists, err := t.Get(namespace, repository, tag); err != nil || !exists {
		log.Error("[ACI API] Not found ACI %v/%v/%v", namespace, repository, acifilename)
		result, _ := json.Marshal(map[string]string{"message": "Not found ACI"})
		return http.StatusNotFound, result
	}

	i := new(models.Image)
	if exists, err := i.Get(t.ImageId); err != nil || !exists {
		log.Error("[ACI API] Not found ACI %v/%v/%v", namespace, repository, acifilename)
		result, _ := json.Marshal(map[string]string{"message": "Not found ACI"})
		return http.StatusNotFound, result
	}

	var filepath string
	if b := strings.Contains(acifilename, ".asc"); b == true {
		filepath = i.SignPath
	} else {
		filepath = i.AciPath
	}

	content, err := ioutil.ReadFile(filepath)
	if err != nil {
		log.Error("[ACI API] Failed to get ACI file %v: %v", filepath, err.Error())

		result, _ := json.Marshal(map[string]string{"message": "Failed to get ACI file"})
		return http.StatusInternalServerError, result
	}

	return http.StatusOK, content
}
开发者ID:yanghongkjxy,项目名称:dockyard,代码行数:39,代码来源:aci.go


示例7: Handler

func (n *notification) Handler(ctx *macaron.Context) {
	namespace := ctx.Params(":namespace")
	repository := ctx.Params(":repository")

	//Notification function just supports DockerV2 now
	r := new(models.Repository)
	if exists, err := r.Get(namespace, repository); err != nil || exists == false {
		return
	}
	if r.Version != setting.APIVERSION_V2 {
		return
	}

	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 exists, _ := i.Get(tarsum); exists == 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 exists, _ := i.Get(tarsum); exists == 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 exists, err := t.Get(namespace, repository, ctx.Params(":tag")); err != nil || !exists {
				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 {
//.........这里部分代码省略.........
开发者ID:maquanyi,项目名称:dockyard,代码行数:101,代码来源:noticehandler.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang metadata.Chunkserver类代码示例发布时间:2022-05-23
下一篇:
Golang models.Repository类代码示例发布时间: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