本文整理汇总了Golang中github.com/containerops/wharf/models.Organization.Username方法的典型用法代码示例。如果您正苦于以下问题:Golang Organization.Username方法的具体用法?Golang Organization.Username怎么用?Golang Organization.Username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/containerops/wharf/models.Organization
的用法示例。
在下文中一共展示了Organization.Username方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PostOrg
func (this *OrganizationWebV1Controller) PostOrg() {
user := new(models.User)
org := new(models.Organization)
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
}
if exist, _, err := user.Has(this.Ctx.Input.Param(":org")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == true {
this.JSONOut(http.StatusBadRequest, "Namespace is occupation already by another user", nil)
return
}
if exist, _, err := org.Has(this.Ctx.Input.Param(":org")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == true {
this.JSONOut(http.StatusBadRequest, "Namespace is occupation already by another organization", nil)
return
}
if err := json.Unmarshal(this.Ctx.Input.CopyBody(), &org); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
}
org.Id = string(utils.GeneralKey(org.Name))
org.Username = user.Username
org.Created = time.Now().UnixNano() / int64(time.Millisecond)
org.Updated = time.Now().UnixNano() / int64(time.Millisecond)
if err := org.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "Organization save error", nil)
return
}
user.Organizations = append(user.Organizations, org.Name)
user.Updated = time.Now().UnixNano() / int64(time.Millisecond)
if err := user.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "User save error", nil)
return
}
memo, _ := json.Marshal(this.Ctx.Input.Header)
user.Log(models.ACTION_ADD_ORG, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, org.Id, memo)
org.Log(models.ACTION_ADD_ORG, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, user.Id, memo)
this.JSONOut(http.StatusOK, "Create organization successfully.", nil)
return
}