|
|
|
@ -20,85 +20,112 @@ import (
|
|
|
|
|
var (
|
|
|
|
|
ts core.TweetSearchService
|
|
|
|
|
ds core.DataService
|
|
|
|
|
dsa core.DataServantA
|
|
|
|
|
oss core.ObjectStorageService
|
|
|
|
|
|
|
|
|
|
onceTs, onceDs, onceOss sync.Once
|
|
|
|
|
_onceInitial sync.Once
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func DataService() core.DataService {
|
|
|
|
|
onceDs.Do(func() {
|
|
|
|
|
var v core.VersionInfo
|
|
|
|
|
if cfg.If("Gorm") {
|
|
|
|
|
ds, v = jinzhu.NewDataService()
|
|
|
|
|
} else if cfg.If("Sqlx") {
|
|
|
|
|
ds, v = sakila.NewDataService()
|
|
|
|
|
} else if cfg.If("Sqlc") && (cfg.If("Postgres") || cfg.If("PostgreSQL")) {
|
|
|
|
|
ds, v = slonik.NewDataService()
|
|
|
|
|
} else {
|
|
|
|
|
// default use gorm as orm for sql database
|
|
|
|
|
ds, v = jinzhu.NewDataService()
|
|
|
|
|
}
|
|
|
|
|
logrus.Infof("use %s as data service with version %s", v.Name(), v.Version())
|
|
|
|
|
})
|
|
|
|
|
lazyInitial()
|
|
|
|
|
return ds
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DataServantA() core.DataServantA {
|
|
|
|
|
lazyInitial()
|
|
|
|
|
return dsa
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ObjectStorageService() core.ObjectStorageService {
|
|
|
|
|
onceOss.Do(func() {
|
|
|
|
|
var v core.VersionInfo
|
|
|
|
|
if cfg.If("AliOSS") {
|
|
|
|
|
oss, v = storage.MustAliossService()
|
|
|
|
|
} else if cfg.If("COS") {
|
|
|
|
|
oss, v = storage.NewCosService()
|
|
|
|
|
} else if cfg.If("HuaweiOBS") {
|
|
|
|
|
oss, v = storage.MustHuaweiobsService()
|
|
|
|
|
} else if cfg.If("MinIO") {
|
|
|
|
|
oss, v = storage.MustMinioService()
|
|
|
|
|
} else if cfg.If("S3") {
|
|
|
|
|
oss, v = storage.MustS3Service()
|
|
|
|
|
logrus.Infof("use S3 as object storage by version %s", v.Version())
|
|
|
|
|
return
|
|
|
|
|
} else if cfg.If("LocalOSS") {
|
|
|
|
|
oss, v = storage.MustLocalossService()
|
|
|
|
|
} else {
|
|
|
|
|
// default use AliOSS as object storage service
|
|
|
|
|
oss, v = storage.MustAliossService()
|
|
|
|
|
logrus.Infof("use default AliOSS as object storage by version %s", v.Version())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
logrus.Infof("use %s as object storage by version %s", v.Name(), v.Version())
|
|
|
|
|
})
|
|
|
|
|
lazyInitial()
|
|
|
|
|
return oss
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TweetSearchService() core.TweetSearchService {
|
|
|
|
|
onceTs.Do(func() {
|
|
|
|
|
var v core.VersionInfo
|
|
|
|
|
ams := newAuthorizationManageService()
|
|
|
|
|
if cfg.If("Zinc") {
|
|
|
|
|
ts, v = search.NewZincTweetSearchService(ams)
|
|
|
|
|
} else if cfg.If("Meili") {
|
|
|
|
|
ts, v = search.NewMeiliTweetSearchService(ams)
|
|
|
|
|
} else {
|
|
|
|
|
// default use Zinc as tweet search service
|
|
|
|
|
ts, v = search.NewZincTweetSearchService(ams)
|
|
|
|
|
}
|
|
|
|
|
logrus.Infof("use %s as tweet search serice by version %s", v.Name(), v.Version())
|
|
|
|
|
|
|
|
|
|
ts = search.NewBridgeTweetSearchService(ts)
|
|
|
|
|
})
|
|
|
|
|
lazyInitial()
|
|
|
|
|
return ts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newAuthorizationManageService() (s core.AuthorizationManageService) {
|
|
|
|
|
func newAuthorizationManageService() (ams core.AuthorizationManageService) {
|
|
|
|
|
if cfg.If("Gorm") {
|
|
|
|
|
s = jinzhu.NewAuthorizationManageService()
|
|
|
|
|
ams = jinzhu.NewAuthorizationManageService()
|
|
|
|
|
} else if cfg.If("Sqlx") {
|
|
|
|
|
s = sakila.NewAuthorizationManageService()
|
|
|
|
|
ams = sakila.NewAuthorizationManageService()
|
|
|
|
|
} else if cfg.If("Sqlc") && (cfg.If("Postgres") || cfg.If("PostgreSQL")) {
|
|
|
|
|
s = slonik.NewAuthorizationManageService()
|
|
|
|
|
ams = slonik.NewAuthorizationManageService()
|
|
|
|
|
} else {
|
|
|
|
|
s = jinzhu.NewAuthorizationManageService()
|
|
|
|
|
ams = jinzhu.NewAuthorizationManageService()
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// lazyInitial do some package lazy initialize for performance
|
|
|
|
|
func lazyInitial() {
|
|
|
|
|
_onceInitial.Do(func() {
|
|
|
|
|
initDsX()
|
|
|
|
|
initOSS()
|
|
|
|
|
initTsX()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initDsX() {
|
|
|
|
|
var dsVer, dsaVer core.VersionInfo
|
|
|
|
|
if cfg.If("Gorm") {
|
|
|
|
|
ds, dsVer = jinzhu.NewDataService()
|
|
|
|
|
dsa, dsaVer = jinzhu.NewDataServantA()
|
|
|
|
|
} else if cfg.If("Sqlx") {
|
|
|
|
|
ds, dsVer = sakila.NewDataService()
|
|
|
|
|
dsa, dsaVer = sakila.NewDataServantA()
|
|
|
|
|
} else if cfg.If("Sqlc") && (cfg.If("Postgres") || cfg.If("PostgreSQL")) {
|
|
|
|
|
ds, dsVer = slonik.NewDataService()
|
|
|
|
|
dsa, dsaVer = slonik.NewDataServantA()
|
|
|
|
|
} else {
|
|
|
|
|
// default use gorm as orm for sql database
|
|
|
|
|
ds, dsVer = jinzhu.NewDataService()
|
|
|
|
|
dsa, dsaVer = jinzhu.NewDataServantA()
|
|
|
|
|
}
|
|
|
|
|
logrus.Infof("use %s as core.DataService with version %s", dsVer.Name(), dsVer.Version())
|
|
|
|
|
logrus.Infof("use %s as core.ServantA with version %s", dsaVer.Name(), dsaVer.Version())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initOSS() {
|
|
|
|
|
var v core.VersionInfo
|
|
|
|
|
if cfg.If("AliOSS") {
|
|
|
|
|
oss, v = storage.MustAliossService()
|
|
|
|
|
} else if cfg.If("COS") {
|
|
|
|
|
oss, v = storage.NewCosService()
|
|
|
|
|
} else if cfg.If("HuaweiOBS") {
|
|
|
|
|
oss, v = storage.MustHuaweiobsService()
|
|
|
|
|
} else if cfg.If("MinIO") {
|
|
|
|
|
oss, v = storage.MustMinioService()
|
|
|
|
|
} else if cfg.If("S3") {
|
|
|
|
|
oss, v = storage.MustS3Service()
|
|
|
|
|
logrus.Infof("use S3 as object storage by version %s", v.Version())
|
|
|
|
|
return
|
|
|
|
|
} else if cfg.If("LocalOSS") {
|
|
|
|
|
oss, v = storage.MustLocalossService()
|
|
|
|
|
} else {
|
|
|
|
|
// default use AliOSS as object storage service
|
|
|
|
|
oss, v = storage.MustAliossService()
|
|
|
|
|
logrus.Infof("use default AliOSS as object storage by version %s", v.Version())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
logrus.Infof("use %s as object storage by version %s", v.Name(), v.Version())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initTsX() {
|
|
|
|
|
var v core.VersionInfo
|
|
|
|
|
ams := newAuthorizationManageService()
|
|
|
|
|
cfg.On(cfg.Actions{
|
|
|
|
|
"Zinc": func() {
|
|
|
|
|
ts, v = search.NewZincTweetSearchService(ams)
|
|
|
|
|
},
|
|
|
|
|
"Meili": func() {
|
|
|
|
|
ts, v = search.NewMeiliTweetSearchService(ams)
|
|
|
|
|
},
|
|
|
|
|
}, func() {
|
|
|
|
|
ts, v = search.NewZincTweetSearchService(ams)
|
|
|
|
|
})
|
|
|
|
|
logrus.Infof("use %s as tweet search serice by version %s", v.Name(), v.Version())
|
|
|
|
|
ts = search.NewBridgeTweetSearchService(ts)
|
|
|
|
|
}
|
|
|
|
|