本文整理汇总了Golang中github.com/couchbase/sync_gateway/db.PrincipalConfig.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang PrincipalConfig.Name方法的具体用法?Golang PrincipalConfig.Name怎么用?Golang PrincipalConfig.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/sync_gateway/db.PrincipalConfig
的用法示例。
在下文中一共展示了PrincipalConfig.Name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updatePrincipal
// Handles PUT and POST for a user or a role.
func (h *handler) updatePrincipal(name string, isUser bool) error {
h.assertAdminOnly()
// Unmarshal the request body into a PrincipalConfig struct:
body, _ := h.readBody()
var newInfo db.PrincipalConfig
var err error
if err = json.Unmarshal(body, &newInfo); err != nil {
return err
}
if h.rq.Method == "POST" {
// On POST, take the name from the "name" property in the request body:
if newInfo.Name == nil {
return base.HTTPErrorf(http.StatusBadRequest, "Missing name property")
}
} else {
// ON PUT, verify the name matches, if given:
if newInfo.Name == nil {
newInfo.Name = &name
} else if *newInfo.Name != name {
return base.HTTPErrorf(http.StatusBadRequest, "Name mismatch (can't change name)")
}
}
internalName := internalUserName(*newInfo.Name)
newInfo.Name = &internalName
replaced, err := h.db.UpdatePrincipal(newInfo, isUser, h.rq.Method != "POST")
if err != nil {
return err
} else if replaced {
// on update with a new password, remove previous user sessions
if newInfo.Password != nil {
err = h.db.DeleteUserSessions(*newInfo.Name)
if err != nil {
return err
}
}
h.writeStatus(http.StatusOK, "OK")
} else {
h.writeStatus(http.StatusCreated, "Created")
}
return nil
}