本文整理匯總了Golang中github.com/MG-RAST/AWE/vendor/github.com/MG-RAST/golib/goweb.Context.RespondWithPaginatedData方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithPaginatedData方法的具體用法?Golang Context.RespondWithPaginatedData怎麽用?Golang Context.RespondWithPaginatedData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MG-RAST/AWE/vendor/github.com/MG-RAST/golib/goweb.Context
的用法示例。
在下文中一共展示了Context.RespondWithPaginatedData方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ReadMany
//.........這裏部分代碼省略.........
}
//getting real active (in-progress) job (some jobs are in "submitted" states but not in the queue,
//because they may have failed and not recovered from the mongodb).
if query.Has("active") {
err := jobs.GetAll(q, order, direction)
if err != nil {
logger.Error("err " + err.Error())
cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
return
}
filtered_jobs := []core.Job{}
act_jobs := core.QMgr.GetActiveJobs()
length := jobs.Length()
skip := 0
count := 0
for i := 0; i < length; i++ {
job := jobs.GetJobAt(i)
if _, ok := act_jobs[job.Id]; ok {
if skip < offset {
skip += 1
continue
}
job.Registered = true
filtered_jobs = append(filtered_jobs, job)
count += 1
if count == limit {
break
}
}
}
cx.RespondWithPaginatedData(filtered_jobs, limit, offset, len(act_jobs))
return
}
//geting suspended job in the current queue (excluding jobs in db but not in qmgr)
if query.Has("suspend") {
err := jobs.GetAll(q, order, direction)
if err != nil {
logger.Error("err " + err.Error())
cx.RespondWithError(http.StatusBadRequest)
return
}
filtered_jobs := []core.Job{}
suspend_jobs := core.QMgr.GetSuspendJobs()
length := jobs.Length()
skip := 0
count := 0
for i := 0; i < length; i++ {
job := jobs.GetJobAt(i)
if _, ok := suspend_jobs[job.Id]; ok {
if skip < offset {
skip += 1
continue
}
job.Registered = true
filtered_jobs = append(filtered_jobs, job)
count += 1
if count == limit {
break
}
}
示例2: ReadMany
// GET: /work
// checkout a workunit with earliest submission time
// to-do: to support more options for workunit checkout
func (cr *WorkController) ReadMany(cx *goweb.Context) {
LogRequest(cx.Request)
// Gather query params
query := &Query{Li: cx.Request.URL.Query()}
if !query.Has("client") { //view workunits
// 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
}
}
// get pagination options
limit := conf.DEFAULT_PAGE_SIZE
offset := 0
order := "info.submittime"
direction := "desc"
if query.Has("limit") {
limit, err = strconv.Atoi(query.Value("limit"))
if err != nil {
cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
return
}
}
if query.Has("offset") {
offset, err = strconv.Atoi(query.Value("offset"))
if err != nil {
cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
return
}
}
if query.Has("order") {
order = query.Value("order")
}
if query.Has("direction") {
direction = query.Value("direction")
}
var workunits []*core.Workunit
if query.Has("state") {
workunits = core.QMgr.ShowWorkunitsByUser(query.Value("state"), u)
} else {
workunits = core.QMgr.ShowWorkunitsByUser("", u)
}
// if using query syntax then do pagination and sorting
if query.Has("query") {
filtered_work := []core.Workunit{}
sorted_work := core.WorkunitsSortby{order, direction, workunits}
sort.Sort(sorted_work)
skip := 0
count := 0
for _, w := range sorted_work.Workunits {
if skip < offset {
skip += 1
continue
}
filtered_work = append(filtered_work, *w)
count += 1
if count == limit {
break
}
}
cx.RespondWithPaginatedData(filtered_work, limit, offset, len(sorted_work.Workunits))
return
} else {
cx.RespondWithData(workunits)
return
}
}
cg, err := request.AuthenticateClientGroup(cx.Request)
if err != nil {
if err.Error() == e.NoAuth || err.Error() == e.UnAuth || err.Error() == e.InvalidAuth {
if conf.CLIENT_AUTH_REQ == true {
cx.RespondWithError(http.StatusUnauthorized)
return
}
} else {
logger.Error("[email protected]: " + err.Error())
cx.RespondWithError(http.StatusInternalServerError)
return
}
}
//.........這裏部分代碼省略.........
示例3: ReadMany
// GET: /cgroup
func (cr *ClientGroupController) ReadMany(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_READ is true, use the public user.
// Otherwise if no auth was provided, throw an error.
// Otherwise, proceed with retrieval of the clientgroups using the user.
if u == nil {
if conf.ANON_CG_READ == true {
u = &user.User{Uuid: "public"}
} else {
cx.RespondWithErrorMessage(e.UnAuth, http.StatusUnauthorized)
return
}
}
// Gather query params
query := &Query{Li: cx.Request.URL.Query()}
// Setup query and clientgroups objects
q := bson.M{}
cgs := core.ClientGroups{}
// Add authorization checking to query if the user is not an admin
if u.Admin == false {
q["$or"] = []bson.M{bson.M{"acl.read": "public"}, bson.M{"acl.read": u.Uuid}, bson.M{"acl.owner": u.Uuid}}
}
limit := conf.DEFAULT_PAGE_SIZE
offset := 0
order := "last_modified"
direction := "desc"
if query.Has("limit") {
limit, err = strconv.Atoi(query.Value("limit"))
if err != nil {
cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
return
}
}
if query.Has("offset") {
offset, err = strconv.Atoi(query.Value("offset"))
if err != nil {
cx.RespondWithErrorMessage(err.Error(), http.StatusBadRequest)
return
}
}
if query.Has("order") {
order = query.Value("order")
}
if query.Has("direction") {
direction = query.Value("direction")
}
// Gather params to make db query. Do not include the following list.
skip := map[string]int{
"limit": 1,
"offset": 1,
"order": 1,
"direction": 1,
}
for key, val := range query.All() {
_, s := skip[key]
if !s {
queryvalues := strings.Split(val[0], ",")
q[key] = bson.M{"$in": queryvalues}
}
}
total, err := cgs.GetPaginated(q, limit, offset, order, direction)
if err != nil {
cx.RespondWithError(http.StatusBadRequest)
return
}
cx.RespondWithPaginatedData(cgs, limit, offset, total)
return
}