package unknownnicks import ( "log" "git.aiterp.net/rpdata/api/internal/store" "git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo" ) var collection *mgo.Collection func list(query interface{}, limit int) ([]models.UnknownNick, error) { size := 64 if limit > 0 { size = limit } posts := make([]models.UnknownNick, 0, size) err := collection.Find(query).Limit(limit).Sort("-score").All(&posts) if err != nil { return nil, err } return posts, nil } func init() { store.HandleInit(func(db *mgo.Database) { collection = db.C("logbot3.unkownnicks") err := collection.EnsureIndexKey("weight") if err != nil { log.Fatalln("init logbot3.unkownnicks:", err) } }) }