當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Repository.Has方法代碼示例

本文整理匯總了Golang中github.com/containerops/wharf/models.Repository.Has方法的典型用法代碼示例。如果您正苦於以下問題:Golang Repository.Has方法的具體用法?Golang Repository.Has怎麽用?Golang Repository.Has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/containerops/wharf/models.Repository的用法示例。


在下文中一共展示了Repository.Has方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetRepositoryTags

func (this *RepoAPIV1Controller) GetRepositoryTags() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read repository json error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read repository no found", nil)
		return
	}

	tag := map[string]string{}

	for _, value := range repo.Tags {
		t := new(models.Tag)
		if err := t.GetById(value); err != nil {
			this.JSONOut(http.StatusBadRequest, "", map[string]string{"message": fmt.Sprintf("%s/%s Tags is not exist", namespace, repository)})
			return
		}

		tag[t.Name] = t.ImageId
	}

	this.JSONOut(http.StatusOK, "", tag)
	return
}
開發者ID:rechen,項目名稱:wharf,代碼行數:29,代碼來源:repoapiv1.go

示例2: GetRepositoryImages

func (this *RepoAPIV1Controller) GetRepositoryImages() {
	namespace := string(this.Ctx.Input.Param(":namespace"))
	repository := string(this.Ctx.Input.Param(":repo_name"))

	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil {
		this.JSONOut(http.StatusBadRequest, "Read repository json error", nil)
		return
	} else if has == false {
		this.JSONOut(http.StatusBadRequest, "Read repository no found", nil)
		return
	}

	repo.Download += 1

	if err := repo.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
	}

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

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(repo.JSON))
	return
}
開發者ID:rechen,項目名稱:wharf,代碼行數:27,代碼來源:repoapiv1.go

示例3: GetTags

func (this *ManifestsAPIV2Controller) GetTags() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil || has == false {
		this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeNameInvalid]}})
		return
	}

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

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

	for _, value := range repo.Tags {
		t := new(models.Tag)
		if err := t.GetById(value); err != nil {
			this.JSONOut(http.StatusBadRequest, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeTagInvalid]}})
			return
		}

		tags = append(tags, t.Name)
	}

	data["tags"] = tags

	this.JSONOut(http.StatusOK, "", data)
	return
}
開發者ID:rechen,項目名稱:wharf,代碼行數:31,代碼來源:manifestsv2.go

示例4: GetRepository

func (this *WebController) GetRepository() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repository")

	repo := new(models.Repository)
	if exist, _, _ := repo.Has(namespace, repository); exist {
		user, exist := this.Ctx.Input.CruSession.Get("user").(models.User)
		if repo.Privated {
			if !exist == true {
				this.Abort("404")
				return
			} else {
				if user.Username != namespace {
					this.Abort("404")
					return
				}
				this.Data["username"] = user.Username
				this.Data["privated"] = repo.Privated
				this.Data["namespace"] = repo.Namespace
				this.Data["repository"] = repo.Repository
				this.Data["created"] = repo.Created
				this.Data["short"] = repo.Short
				this.Data["description"] = string(github_flavored_markdown.Markdown([]byte(repo.Description)))
				this.Data["download"] = repo.Download
				this.Data["comments"] = len(repo.Comments)
				this.Data["starts"] = len(repo.Starts)

				this.TplNames = "repository.html"
				this.Render()
				return
			}
		} else {
			this.Data["username"] = user.Username
			this.Data["privated"] = repo.Privated
			this.Data["namespace"] = repo.Namespace
			this.Data["repository"] = repo.Repository
			this.Data["created"] = repo.Created
			this.Data["short"] = repo.Short
			this.Data["description"] = string(github_flavored_markdown.Markdown([]byte(repo.Description)))
			this.Data["download"] = repo.Download
			this.Data["comments"] = len(repo.Comments)
			this.Data["starts"] = len(repo.Starts)

			this.TplNames = "repository.html"
			this.Render()
			return
		}
	} else {
		this.Abort("404")
		return
	}
	return
}
開發者ID:rechen,項目名稱:wharf,代碼行數:53,代碼來源:web.go

示例5: checkRepositoriesPrivate

func checkRepositoriesPrivate(namespace, repository string) bool {
	repo := new(models.Repository)

	if has, _, err := repo.Has(namespace, repository); err != nil || has == false {
		return false
	} else if has == true {
		if repo.Privated == true {
			return false
		} else {
			return true
		}
	}

	return false
}
開發者ID:rechen,項目名稱:wharf,代碼行數:15,代碼來源:auth.go

示例6: checkOrgRepositoryPermission

func checkOrgRepositoryPermission(user *models.User, namespace, repository string, permission int) bool {
	owner := false

	//Check Org exists
	org := new(models.Organization)
	if has, _, _ := org.Has(namespace); has == false {
		return false
	}

	//Check Owner, don't care Join team
	for _, k := range user.Organizations {
		if org.Id == k {
			owner = true
		}
	}

	//Check Repository
	repo := new(models.Repository)
	if has, _, _ := repo.Has(namespace, repository); has == false {
		if owner == true {
			return true
		} else {
			return false
		}
	}

	if repo.Privated == false && permission == PERMISSION_READ {
		return true
	}

	//Loop Team
	for _, k := range user.JoinTeams {
		team := new(models.Team)

		if err := team.GetById(k); err != nil {
			return false
		}

		//TODO Check Team Perimssion

	}

	return false
}
開發者ID:rechen,項目名稱:wharf,代碼行數:44,代碼來源:auth.go


注:本文中的github.com/containerops/wharf/models.Repository.Has方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。