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


Golang Organization.GetByName方法代码示例

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


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

示例1: GetJoinOrgs

func (this *OrganizationWebV1Controller) GetJoinOrgs() {
	user := new(models.User)
	orgs := make([]models.Organization, 0)

	if exist, _, err := user.Has(this.Ctx.Input.Param(":username")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	} else if exist == false {
		this.JSONOut(http.StatusBadRequest, "User not exist", nil)
		return
	}

	for _, name := range user.JoinOrganizations {
		org := new(models.Organization)
		if err := org.GetByName(name); err != nil {
			this.JSONOut(http.StatusBadRequest, "Get organizations error", nil)
			return
		}

		orgs = append(orgs, *org)
	}

	this.JSONOut(http.StatusOK, "", orgs)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:25,代码来源:orgwebv1.go

示例2: GetTeams

func (this *TeamWebV1Controller) GetTeams() {
	if _, exist := this.Ctx.Input.CruSession.Get("user").(models.User); exist == false {
		this.JSONOut(http.StatusBadRequest, "", map[string]string{"message": "Session load failure", "url": "/auth"})
		return
	}

	teams := make([]models.Team, 0)

	org := new(models.Organization)
	if err := org.GetByName(this.Ctx.Input.Param(":org")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	for _, name := range org.Teams {
		team := new(models.Team)
		if err := team.GetByName(org.Name, name); err != nil {
			this.JSONOut(http.StatusBadRequest, err.Error(), nil)
			return
		}

		teams = append(teams, *team)
	}

	this.JSONOut(http.StatusOK, "", teams)
	return
}
开发者ID:rechen,项目名称:wharf,代码行数:27,代码来源:teamwebv1.go

示例3: PutTeamAddMember

func (this *TeamWebV1Controller) PutTeamAddMember() {
	if _, exist := this.Ctx.Input.CruSession.Get("user").(models.User); exist == false {
		this.JSONOut(http.StatusBadRequest, "", map[string]string{"message": "Session load failure", "url": "/auth"})
		return
	}

	org := new(models.Organization)
	if err := org.GetByName(this.Ctx.Input.Param(":org")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	team := new(models.Team)
	if err := team.GetByName(this.Ctx.Input.Param(":org"), this.Ctx.Input.Param(":team")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	user := new(models.User)
	if exist, _, err := user.Has(this.Ctx.Input.Param(":username")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	} else if exist == false {
		this.JSONOut(http.StatusBadRequest, "User not found", nil)
		return
	}

	exist := false
	for _, u := range team.Users {
		if u == this.Ctx.Input.Param(":username") {
			exist = true
		}
	}

	if exist == true {
		this.JSONOut(http.StatusBadRequest, "User already in team", nil)
		return
	} else {
		team.Users = append(team.Users, this.Ctx.Input.Param(":username"))

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

		this.JSONOut(http.StatusOK, "", user)
		return
	}
}
开发者ID:rechen,项目名称:wharf,代码行数:49,代码来源:teamwebv1.go


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