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.
paopao-ce/internal/dao/dao.go

58 lines
1.3 KiB

package dao
import (
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/zinc"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
var (
_ core.DataService = (*dataServant)(nil)
_ core.AttachmentCheckService = (*attachmentCheckServant)(nil)
_ core.TweetSearchService = (*zincTweetSearchServant)(nil)
)
type dataServant struct {
useCacheIndex bool
cacheIndex core.CacheIndexService
engine *gorm.DB
zinc *zinc.ZincClient
}
type attachmentCheckServant struct {
domain string
}
func NewDataService() core.DataService {
client := zinc.NewClient(conf.ZincSetting)
ds := &dataServant{
engine: conf.DBEngine,
zinc: client,
}
// initialize CacheIndex if needed
ds.useCacheIndex = true
if conf.CfgIf("SimpleCacheIndex") {
ds.cacheIndex = newSimpleCacheIndexServant(ds.getIndexPosts)
} else if conf.CfgIf("BigCacheIndex") {
ds.cacheIndex = newBigCacheIndexServant(ds.getIndexPosts)
} else {
ds.useCacheIndex = false
}
if ds.useCacheIndex {
logrus.Infof("use %s as cache index service by version: %s", ds.cacheIndex.Name(), ds.cacheIndex.Version())
}
return ds
}
func NewAttachmentCheckerService() core.AttachmentCheckService {
return &attachmentCheckServant{
domain: getOssDomain(),
}
}