本文整理匯總了Golang中github.com/MG-RAST/AWE/vendor/github.com/MG-RAST/golib/goweb.Context.RespondWithOK方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithOK方法的具體用法?Golang Context.RespondWithOK怎麽用?Golang Context.RespondWithOK使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/AWE/vendor/github.com/MG-RAST/golib/goweb.Context
的用法示例。
在下文中一共展示了Context.RespondWithOK方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Delete
// DELETE: /cgroup/{id}
func (cr *ClientGroupController) Delete(id string, cx *goweb.Context) {
LogRequest(cx.Request)
// Try to authenticate user.
u, err := request.Authenticate(cx.Request)
if err != nil && err.Error() != e.NoAuth {
cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
return
}
// If no auth was provided and ANON_CG_DELETE is true, use the public user.
// Otherwise if no auth was provided, throw an error.
// Otherwise, proceed with deletion of the clientgroup using the user.
if u == nil {
if conf.ANON_CG_DELETE == true {
u = &user.User{Uuid: "public"}
} else {
cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
return
}
}
// Load clientgroup by id
cg, err := core.LoadClientGroup(id)
if err != nil {
if err == mgo.ErrNotFound {
cx.RespondWithNotFound()
} else {
// In theory the db connection could be lost between
// checking user and load but seems unlikely.
cx.RespondWithErrorMessage("clientgroup id not found:"+id, http.StatusBadRequest)
}
return
}
// User must have delete permissions on clientgroup or be clientgroup owner or be an admin or the clientgroup is publicly deletable.
// The other possibility is that public deletion of clientgroups is enabled and the clientgroup is publicly deletable.
rights := cg.Acl.Check(u.Uuid)
public_rights := cg.Acl.Check("public")
if (u.Uuid != "public" && (cg.Acl.Owner == u.Uuid || rights["delete"] == true || u.Admin == true || public_rights["delete"] == true)) ||
(u.Uuid == "public" && conf.ANON_CG_DELETE == true && public_rights["delete"] == true) {
err := core.DeleteClientGroup(id)
if err != nil {
cx.RespondWithErrorMessage("Could not delete clientgroup.", http.StatusInternalServerError)
return
}
cx.RespondWithOK()
return
}
cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
return
}
示例2: Options
// OPTIONS: /work
func (cr *WorkController) Options(cx *goweb.Context) {
LogRequest(cx.Request)
cx.RespondWithOK()
return
}