Merge branch 'x/gorm' into x/sqlc

r/paopao-ce-pro
Michael Li 2 years ago
commit 95b871c039
No known key found for this signature in database

@ -36,8 +36,8 @@ type DataService interface {
AttachmentCheckService AttachmentCheckService
} }
// DataServantA 数据服务集成(版本A) // WebDataServantA Web数据服务集成(版本A)
type DataServantA interface { type WebDataServantA interface {
// 话题服务 // 话题服务
TopicServantA TopicServantA

@ -20,8 +20,8 @@ import (
var ( var (
ts core.TweetSearchService ts core.TweetSearchService
ds core.DataService ds core.DataService
dsa core.DataServantA
oss core.ObjectStorageService oss core.ObjectStorageService
webDsa core.WebDataServantA
_onceInitial sync.Once _onceInitial sync.Once
) )
@ -31,9 +31,9 @@ func DataService() core.DataService {
return ds return ds
} }
func DataServantA() core.DataServantA { func WebDataServantA() core.WebDataServantA {
lazyInitial() lazyInitial()
return dsa return webDsa
} }
func ObjectStorageService() core.ObjectStorageService { func ObjectStorageService() core.ObjectStorageService {
@ -72,17 +72,17 @@ func initDsX() {
var dsVer, dsaVer core.VersionInfo var dsVer, dsaVer core.VersionInfo
if cfg.If("Gorm") { if cfg.If("Gorm") {
ds, dsVer = jinzhu.NewDataService() ds, dsVer = jinzhu.NewDataService()
dsa, dsaVer = jinzhu.NewDataServantA() webDsa, dsaVer = jinzhu.NewWebDataServantA()
} else if cfg.If("Sqlx") { } else if cfg.If("Sqlx") {
ds, dsVer = sakila.NewDataService() ds, dsVer = sakila.NewDataService()
dsa, dsaVer = sakila.NewDataServantA() webDsa, dsaVer = sakila.NewWebDataServantA()
} else if cfg.If("Sqlc") && (cfg.If("Postgres") || cfg.If("PostgreSQL")) { } else if cfg.If("Sqlc") && (cfg.If("Postgres") || cfg.If("PostgreSQL")) {
ds, dsVer = slonik.NewDataService() ds, dsVer = slonik.NewDataService()
dsa, dsaVer = slonik.NewDataServantA() webDsa, dsaVer = slonik.NewWebDataServantA()
} else { } else {
// default use gorm as orm for sql database // default use gorm as orm for sql database
ds, dsVer = jinzhu.NewDataService() ds, dsVer = jinzhu.NewDataService()
dsa, dsaVer = jinzhu.NewDataServantA() webDsa, dsaVer = jinzhu.NewWebDataServantA()
} }
logrus.Infof("use %s as core.DataService with version %s", dsVer.Name(), dsVer.Version()) 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()) logrus.Infof("use %s as core.ServantA with version %s", dsaVer.Name(), dsaVer.Version())

@ -24,8 +24,8 @@ var (
_ core.DataService = (*dataSrv)(nil) _ core.DataService = (*dataSrv)(nil)
_ core.VersionInfo = (*dataSrv)(nil) _ core.VersionInfo = (*dataSrv)(nil)
_ core.DataServantA = (*dataSrvA)(nil) _ core.WebDataServantA = (*webDataSrvA)(nil)
_ core.VersionInfo = (*dataSrvA)(nil) _ core.VersionInfo = (*webDataSrvA)(nil)
_onceInitial sync.Once _onceInitial sync.Once
) )
@ -46,7 +46,7 @@ type dataSrv struct {
core.AttachmentCheckService core.AttachmentCheckService
} }
type dataSrvA struct { type webDataSrvA struct {
core.TopicServantA core.TopicServantA
core.TweetServantA core.TweetServantA
core.TweetManageServantA core.TweetManageServantA
@ -109,12 +109,10 @@ func NewDataService() (core.DataService, core.VersionInfo) {
return ds, ds return ds, ds
} }
func NewDataServantA() (core.DataServantA, core.VersionInfo) { func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) {
lazyInitial() lazyInitial()
db := conf.MustGormDB() db := conf.MustGormDB()
ds := &webDataSrvA{
ds := &dataSrvA{
TopicServantA: newTopicServantA(db), TopicServantA: newTopicServantA(db),
TweetServantA: newTweetServantA(db), TweetServantA: newTweetServantA(db),
TweetManageServantA: newTweetManageServantA(db), TweetManageServantA: newTweetManageServantA(db),
@ -135,11 +133,11 @@ func (s *dataSrv) Version() *semver.Version {
return semver.MustParse("v0.2.0") return semver.MustParse("v0.2.0")
} }
func (s *dataSrvA) Name() string { func (s *webDataSrvA) Name() string {
return "Gorm" return "Gorm"
} }
func (s *dataSrvA) Version() *semver.Version { func (s *webDataSrvA) Version() *semver.Version {
return semver.MustParse("v0.1.0") return semver.MustParse("v0.1.0")
} }

@ -17,7 +17,7 @@ func NewDataService() (core.DataService, core.VersionInfo) {
return nil, nil return nil, nil
} }
func NewDataServantA() (core.DataServantA, core.VersionInfo) { func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) {
logrus.Fatal("not support now") logrus.Fatal("not support now")
return nil, nil return nil, nil
} }

@ -98,7 +98,7 @@ func NewDataService() (core.DataService, core.VersionInfo) {
return ds, ds return ds, ds
} }
func NewDataServantA() (core.DataServantA, core.VersionInfo) { func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) {
logrus.Fatal("not support now") logrus.Fatal("not support now")
return nil, nil return nil, nil
} }

@ -26,7 +26,7 @@ type BaseServant types.Empty
type DaoServant struct { type DaoServant struct {
Redis *redis.Client Redis *redis.Client
Dsa core.DataServantA Dsa core.WebDataServantA
Ds core.DataService Ds core.DataService
Ts core.TweetSearchService Ts core.TweetSearchService
} }
@ -119,7 +119,7 @@ func RenderAny(c *gin.Context, data any, err mir.Error) {
func NewDaoServant() *DaoServant { func NewDaoServant() *DaoServant {
return &DaoServant{ return &DaoServant{
Redis: conf.MustRedis(), Redis: conf.MustRedis(),
Dsa: dao.DataServantA(), Dsa: dao.WebDataServantA(),
Ds: dao.DataService(), Ds: dao.DataService(),
Ts: dao.TweetSearchService(), Ts: dao.TweetSearchService(),
} }

@ -170,9 +170,9 @@ func (s *privSrv) UploadAttachment(req *web.UploadAttachmentReq) (*web.UploadAtt
attachment.ImgWidth, attachment.ImgHeight = getImageSize(src.Bounds()) attachment.ImgWidth, attachment.ImgHeight = getImageSize(src.Bounds())
} }
} }
attachment.ID, err = s.Ds.CreateAttachment(attachment) attachment.ID, err = s.Dsa.CreateAttachment(attachment)
if err != nil { if err != nil {
logrus.Errorf("Ds.CreateAttachment err: %s", err) logrus.Errorf("Dsa.CreateAttachment err: %s", err)
return nil, _errFileUploadFailed return nil, _errFileUploadFailed
} }

Loading…
Cancel
Save