41 lines
777 B
Go
41 lines
777 B
Go
package authoritymod
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"91porn-server/common/log"
|
|
)
|
|
|
|
// AuthorPage AuthorPage
|
|
type AuthorPage struct {
|
|
Total int `json:"total" bson:"total"`
|
|
List []AuthorityDoc `json:"list" bson:"list"`
|
|
}
|
|
|
|
// AuthorPages AuthorPages
|
|
func AuthorPages(skip int64, limit int64) (page AuthorPage, err error) {
|
|
pipeline := []M{
|
|
M{
|
|
"$facet": M{
|
|
"total": A{M{"$count": "total"}},
|
|
"list": A{
|
|
M{"$sort": M{"role": 1}},
|
|
M{"$skip": skip},
|
|
M{"$limit": limit},
|
|
},
|
|
},
|
|
},
|
|
M{
|
|
"$project": M{
|
|
"total": M{"$arrayElemAt": A{"$total.total", 0}},
|
|
"list": 1,
|
|
},
|
|
},
|
|
}
|
|
if err = coll(nil).AggregateDecode(&page, pipeline); err != nil {
|
|
log.ZapLog.Error(fmt.Sprintf("coll:%s Page error:%+v:", table, err))
|
|
return
|
|
}
|
|
return
|
|
}
|