本文整理汇总了Golang中github.com/jaredwilkening/goweb.Context.RespondWithPaginatedData方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.RespondWithPaginatedData方法的具体用法?Golang Context.RespondWithPaginatedData怎么用?Golang Context.RespondWithPaginatedData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jaredwilkening/goweb.Context
的用法示例。
在下文中一共展示了Context.RespondWithPaginatedData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ReadMany
// GET: /node
// To do:
// - Iterate node queries
func (cr *NodeController) ReadMany(cx *goweb.Context) {
// Log Request and check for Auth
LogRequest(cx.Request)
u, err := AuthenticateRequest(cx.Request)
if err != nil && err.Error() != e.NoAuth {
handleAuthError(err, cx)
return
}
// Gather query params
query := &Query{list: cx.Request.URL.Query()}
// Setup query and nodes objects
q := bson.M{}
nodes := store.Nodes{}
if u != nil {
// Admin sees all
if !u.Admin {
q["$or"] = []bson.M{bson.M{"acl.read": []string{}}, bson.M{"acl.read": u.Uuid}, bson.M{"acl.owner": u.Uuid}}
}
} else {
if conf.ANON_READ {
// select on only nodes with no read rights set
q["acl.read"] = []string{}
} else {
cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
return
}
}
// Gather params to make db query. Do not include the
// following list.
paramlist := map[string]int{"limit": 1, "offset": 1, "query": 1, "querynode": 1}
if query.Has("query") {
for key, val := range query.All() {
_, s := paramlist[key]
if !s {
q[fmt.Sprintf("attributes.%s", key)] = val[0]
}
}
} else if query.Has("querynode") {
for key, val := range query.All() {
if key == "type" {
querytypes := strings.Split(query.Value("type"), ",")
q["type"] = bson.M{"$all": querytypes}
} else {
_, s := paramlist[key]
if !s {
q[key] = val[0]
}
}
}
}
// defaults
limit := 25
offset := 0
if query.Has("limit") {
limit = ToInt(query.Value("limit"))
}
if query.Has("offset") {
offset = ToInt(query.Value("offset"))
}
// Get nodes from db
count, err := nodes.GetPaginated(q, limit, offset)
if err != nil {
log.Error("err " + err.Error())
cx.RespondWithError(http.StatusBadRequest)
return
}
cx.RespondWithPaginatedData(nodes, limit, offset, count)
return
}