func NewUnread(repo content.Repo, l webfw.Logger) Unread { go func() { repo.DeleteStaleUnreadRecords() for range time.Tick(24 * time.Hour) { repo.DeleteStaleUnreadRecords() } }() return Unread{logger: l} }
func getReadeefUser(repo content.Repo, md5hex string, log webfw.Logger) content.User { md5, err := hex.DecodeString(md5hex) if err != nil { log.Printf("Error decoding hex api_key") return nil } user := repo.UserByMD5Api(md5) if user.HasErr() { log.Printf("Error getting user by md5api field: %v\n", user.Err()) return nil } return user }
func (e Elastic) IndexAllFeeds(repo content.Repo) error { e.logger.Infoln("Indexing all articles") for _, f := range repo.AllFeeds() { articles := f.AllArticles() if f.HasErr() { return f.Err() } if err := e.BatchIndex(articles, data.BatchAdd); err != nil { return err } } return repo.Err() }
func initAdminUser(repo content.Repo, secret []byte) error { users := repo.AllUsers() if repo.HasErr() { return repo.Err() } if len(users) > 0 { return nil } u := repo.User() u.Data(data.User{Login: data.Login("admin"), Active: true, Admin: true}) u.Password("admin", secret) u.Update() return u.Err() }