本文整理匯總了Golang中github.com/MG-RAST/AWE/vendor/github.com/MG-RAST/golib/goweb.Context.RespondWithNotFound方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithNotFound方法的具體用法?Golang Context.RespondWithNotFound怎麽用?Golang Context.RespondWithNotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/AWE/vendor/github.com/MG-RAST/golib/goweb.Context
的用法示例。
在下文中一共展示了Context.RespondWithNotFound方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Delete
// DELETE: /job/{id}
func (cr *JobController) 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)
}
// If no auth was provided, and anonymous delete is allowed, use the public user
if u == nil {
if conf.ANON_DELETE == true {
u = &user.User{Uuid: "public"}
} else {
cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
return
}
}
if err = core.QMgr.DeleteJobByUser(id, u); err != nil {
if err == mgo.ErrNotFound {
cx.RespondWithNotFound()
return
} else if err.Error() == e.UnAuth {
cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
return
} else {
cx.RespondWithErrorMessage("fail to delete job: "+id, http.StatusBadRequest)
return
}
}
cx.RespondWithData("job deleted: " + id)
return
}
示例2: 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
}
示例3: Update
// PUT: /job/{id} -> used for job manipulation
func (cr *JobController) Update(id string, cx *goweb.Context) {
// Log Request and check for Auth
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 anonymous write is allowed, use the public user
if u == nil {
if conf.ANON_WRITE == true {
u = &user.User{Uuid: "public"}
} else {
cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
return
}
}
// Load job by id
job, err := core.LoadJob(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.
// logger.Error("[email protected]_Read:LoadJob: " + id + ":" + err.Error())
cx.RespondWithErrorMessage("job not found:"+id, http.StatusBadRequest)
}
return
}
// User must have write permissions on job or be job owner or be an admin
rights := job.Acl.Check(u.Uuid)
if job.Acl.Owner != u.Uuid && rights["write"] == false && u.Admin == false {
cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
return
}
// Gather query params
query := &Query{Li: cx.Request.URL.Query()}
if query.Has("resume") { // to resume a suspended job
if err := core.QMgr.ResumeSuspendedJob(id); err != nil {
cx.RespondWithErrorMessage("fail to resume job: "+id+" "+err.Error(), http.StatusBadRequest)
return
}
cx.RespondWithData("job resumed: " + id)
return
}
if query.Has("suspend") { // to suspend an in-progress job
if err := core.QMgr.SuspendJob(id, "manually suspended", ""); err != nil {
cx.RespondWithErrorMessage("fail to suspend job: "+id+" "+err.Error(), http.StatusBadRequest)
return
}
cx.RespondWithData("job suspended: " + id)
return
}
if query.Has("resubmit") || query.Has("reregister") { // to re-submit a job from mongodb
if err := core.QMgr.ResubmitJob(id); err != nil {
cx.RespondWithErrorMessage("fail to resubmit job: "+id+" "+err.Error(), http.StatusBadRequest)
return
}
cx.RespondWithData("job resubmitted: " + id)
return
}
if query.Has("recompute") { // to recompute a job from task i, the successive/downstream tasks of i will all be computed
stage := query.Value("recompute")
if stage == "" {
cx.RespondWithErrorMessage("lacking stage id from which the recompute starts", http.StatusBadRequest)
return
}
if err := core.QMgr.RecomputeJob(id, stage); err != nil {
cx.RespondWithErrorMessage("fail to recompute job: "+id+" "+err.Error(), http.StatusBadRequest)
return
}
cx.RespondWithData("job recompute started: " + id)
return
}
if query.Has("clientgroup") { // change the clientgroup attribute of the job
newgroup := query.Value("clientgroup")
if newgroup == "" {
cx.RespondWithErrorMessage("lacking clientgroup name", http.StatusBadRequest)
return
}
if err := core.QMgr.UpdateGroup(id, newgroup); err != nil {
cx.RespondWithErrorMessage("failed to update group for job: "+id+" "+err.Error(), http.StatusBadRequest)
return
}
cx.RespondWithData("job group updated: " + id + " to " + newgroup)
return
}
if query.Has("priority") { // change the priority attribute of the job
priority_str := query.Value("priority")
if priority_str == "" {
cx.RespondWithErrorMessage("lacking priority value", http.StatusBadRequest)
//.........這裏部分代碼省略.........
示例4: Read
// GET: /job/{id}
func (cr *JobController) Read(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 anonymous read is allowed, use the public user
if u == nil {
if conf.ANON_READ == true {
u = &user.User{Uuid: "public"}
} else {
cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
return
}
}
// Load job by id
job, err := core.LoadJob(id)
if err != nil {
cx.RespondWithErrorMessage("job not found:"+id, http.StatusBadRequest)
return
}
// User must have read permissions on job or be job owner or be an admin
rights := job.Acl.Check(u.Uuid)
prights := job.Acl.Check("public")
if job.Acl.Owner != u.Uuid && rights["read"] == false && u.Admin == false && prights["read"] == false {
cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
return
}
// Gather query params
query := &Query{Li: cx.Request.URL.Query()}
if query.Has("perf") {
//Load job perf by id
perf, err := core.LoadJobPerf(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.
logger.Error("[email protected]: " + id + ":" + err.Error())
cx.RespondWithErrorMessage("job perf stats not found:"+id, http.StatusBadRequest)
}
return
}
cx.RespondWithData(perf)
return //done with returning perf, no need to load job further.
}
if query.Has("position") {
if job.State != "queued" && job.State != "in-progress" {
cx.RespondWithErrorMessage("job is not queued or in-progress, job state:"+job.State, http.StatusBadRequest)
return
}
// Retrieve the job's approximate position in the queue (this is a rough estimate since jobs are not actually in a queue)
q := bson.M{}
qState := bson.M{} // query job state
qPriority := bson.M{} // query job priority
qCgroup := bson.M{} // query job clietgroup
qState["$or"] = []bson.M{bson.M{"state": core.JOB_STAT_INIT}, bson.M{"state": core.JOB_STAT_QUEUED}, bson.M{"state": core.JOB_STAT_INPROGRESS}}
qPriority["$or"] = []bson.M{bson.M{"info.priority": bson.M{"$gt": job.Info.Priority}}, bson.M{"$and": []bson.M{bson.M{"info.priority": job.Info.Priority}, bson.M{"info.submittime": bson.M{"$lt": job.Info.SubmitTime}}}}}
var cgroups []bson.M
for _, value := range strings.Split(job.Info.ClientGroups, ",") {
cgroups = append(cgroups, bson.M{"info.clientgroups": bson.M{"$regex": value}})
}
qCgroup["$or"] = cgroups
q["$and"] = []bson.M{qState, qPriority, qCgroup}
if count, err := core.GetJobCount(q); err != nil {
cx.RespondWithErrorMessage("error retrieving job position in queue", http.StatusInternalServerError)
} else {
m := make(map[string]int)
m["position"] = count + 1
cx.RespondWithData(m)
}
return
}
if core.QMgr.IsJobRegistered(id) {
job.Registered = true
} else {
job.Registered = false
}
if query.Has("export") {
target := query.Value("export")
if target == "" {
cx.RespondWithErrorMessage("lacking stage id from which the recompute starts", http.StatusBadRequest)
//.........這裏部分代碼省略.........