package svc import ( "github.com/zeromicro/go-zero/core/stores/redis" "github.com/zeromicro/go-zero/core/stores/sqlx" "trasfer_middleware/cmd/rpc/internal/config" "trasfer_middleware/cmd/rpc/internal/logic/po/zltx" "trasfer_middleware/genModel" "trasfer_middleware/genModel/marketReseller" ) type ServiceContext struct { Config config.Config RedisClient *redis.Redis DbRead *Model DbWrite *Model DbReseller *MarkerReseller ZltxOrder *zltx.ZltxOrder } func NewServiceContext(c config.Config) *ServiceContext { return &ServiceContext{ Config: c, RedisClient: redis.MustNewRedis(redis.RedisConf{ Host: c.Redis.Host, Type: c.Redis.Type, Pass: c.Redis.Pass, }), DbRead: DbModel(c.DB.Master.DataSource, c), DbWrite: DbModel(c.DB.Slave.DataSource, c), DbReseller: ResellerModel(c.DB.MarketReseller.DataSource, c), ZltxOrder: zltx.NewZltxOrder(c.ZLTX), } } func DbModel(datasource string, c config.Config) *Model { sqlConn := sqlx.NewMysql(datasource) return &Model{ ClientModel: genModel.NewServerClientModel(sqlConn, c.Cache), } } type Model struct { ClientModel genModel.ServerClientModel } func ResellerModel(datasource string, c config.Config) *MarkerReseller { sqlConn := sqlx.NewMysql(datasource) return &MarkerReseller{ ResellerMerchant: marketReseller.NewResellerMerchantModel(sqlConn, c.Cache), } } type MarkerReseller struct { ResellerMerchant marketReseller.ResellerMerchantModel }