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
}
// DataServantA 数据服务集成(版本A)
type DataServantA interface {
// WebDataServantA Web数据服务集成(版本A)
type WebDataServantA interface {
// 话题服务
TopicServantA

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

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

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

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

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

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

Loading…
Cancel
Save