48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
|
|
package services
|
||
|
|
|
||
|
|
import (
|
||
|
|
"path/filepath"
|
||
|
|
|
||
|
|
"lmika.dev/lmika/weiro/config"
|
||
|
|
"lmika.dev/lmika/weiro/providers/db"
|
||
|
|
"lmika.dev/lmika/weiro/services/auth"
|
||
|
|
"lmika.dev/lmika/weiro/services/posts"
|
||
|
|
"lmika.dev/lmika/weiro/services/publisher"
|
||
|
|
"lmika.dev/lmika/weiro/services/sites"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Services struct {
|
||
|
|
DB *db.Provider
|
||
|
|
Auth *auth.Service
|
||
|
|
Publisher *publisher.Publisher
|
||
|
|
PublisherQueue *publisher.Queue
|
||
|
|
Posts *posts.Service
|
||
|
|
Sites *sites.Service
|
||
|
|
}
|
||
|
|
|
||
|
|
func New(cfg config.Config) (*Services, error) {
|
||
|
|
dbp, err := db.New(filepath.Join(cfg.DataDir, "weiro.db"))
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
authSvc := auth.New(dbp)
|
||
|
|
publisherSvc := publisher.New(dbp)
|
||
|
|
publisherQueue := publisher.NewQueue(publisherSvc)
|
||
|
|
postService := posts.New(dbp, publisherQueue)
|
||
|
|
siteService := sites.New(dbp)
|
||
|
|
|
||
|
|
return &Services{
|
||
|
|
DB: dbp,
|
||
|
|
Auth: authSvc,
|
||
|
|
Publisher: publisherSvc,
|
||
|
|
PublisherQueue: publisherQueue,
|
||
|
|
Posts: postService,
|
||
|
|
Sites: siteService,
|
||
|
|
}, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *Services) Close() error {
|
||
|
|
return s.DB.Close()
|
||
|
|
}
|