mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.4 KiB
88 lines
2.4 KiB
// Core service implement base gorm+mysql/postgresql/sqlite3.
|
|
// Jinzhu is the primary developer of gorm so use his name as
|
|
// package name as a saluter.
|
|
|
|
package jinzhu
|
|
|
|
import (
|
|
"github.com/Masterminds/semver/v3"
|
|
"github.com/alimy/cfg"
|
|
"github.com/rocboss/paopao-ce/internal/conf"
|
|
"github.com/rocboss/paopao-ce/internal/core"
|
|
"github.com/rocboss/paopao-ce/internal/dao/cache"
|
|
"github.com/rocboss/paopao-ce/internal/dao/security"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var (
|
|
_ core.DataService = (*dataServant)(nil)
|
|
_ core.VersionInfo = (*dataServant)(nil)
|
|
)
|
|
|
|
type dataServant struct {
|
|
core.IndexPostsService
|
|
core.WalletService
|
|
core.MessageService
|
|
core.TopicService
|
|
core.TweetService
|
|
core.TweetManageService
|
|
core.TweetHelpService
|
|
core.CommentService
|
|
core.CommentManageService
|
|
core.UserManageService
|
|
core.ContactManageService
|
|
core.SecurityService
|
|
core.AttachmentCheckService
|
|
}
|
|
|
|
func NewDataService() (core.DataService, core.VersionInfo) {
|
|
// initialize CacheIndex if needed
|
|
var (
|
|
c core.CacheIndexService
|
|
v core.VersionInfo
|
|
)
|
|
db := conf.MustGormDB()
|
|
pvs := security.NewPhoneVerifyService()
|
|
|
|
i := newIndexPostsService(db)
|
|
if cfg.If("SimpleCacheIndex") {
|
|
i = newSimpleIndexPostsService(db)
|
|
c, v = cache.NewSimpleCacheIndexService(i)
|
|
} else if cfg.If("BigCacheIndex") {
|
|
a := newAuthorizationManageService(db)
|
|
c, v = cache.NewBigCacheIndexService(i, a)
|
|
} else {
|
|
c, v = cache.NewNoneCacheIndexService(i)
|
|
}
|
|
logrus.Infof("use %s as cache index service by version: %s", v.Name(), v.Version())
|
|
|
|
ds := &dataServant{
|
|
IndexPostsService: c,
|
|
WalletService: newWalletService(db),
|
|
MessageService: newMessageService(db),
|
|
TopicService: newTopicService(db),
|
|
TweetService: newTweetService(db),
|
|
TweetManageService: newTweetManageService(db, c),
|
|
TweetHelpService: newTweetHelpService(db),
|
|
CommentService: newCommentService(db),
|
|
CommentManageService: newCommentManageService(db),
|
|
UserManageService: newUserManageService(db),
|
|
ContactManageService: newContactManageService(db),
|
|
SecurityService: newSecurityService(db, pvs),
|
|
AttachmentCheckService: security.NewAttachmentCheckService(),
|
|
}
|
|
return ds, ds
|
|
}
|
|
|
|
func NewAuthorizationManageService() core.AuthorizationManageService {
|
|
return newAuthorizationManageService(conf.MustGormDB())
|
|
}
|
|
|
|
func (s *dataServant) Name() string {
|
|
return "Gorm"
|
|
}
|
|
|
|
func (s *dataServant) Version() *semver.Version {
|
|
return semver.MustParse("v0.2.0")
|
|
}
|