本文整理汇总了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
}
示例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
}
示例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
}
}