55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package svc
|
|
|
|
import (
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
"trasfer_middleware/cmd/rpc/internal/config"
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/market"
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/new_market"
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/physical"
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/rs"
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/zltx"
|
|
mqs "trasfer_middleware/until/mq"
|
|
)
|
|
|
|
type ServiceContext struct {
|
|
Config config.Config
|
|
RedisClient *redis.Redis
|
|
ZltxOrder *zltx.ZltxOrder
|
|
Market *market.Market
|
|
RS *rs.RS
|
|
NewMarket *new_market.NewMarketStruct
|
|
Physical *physical.Physical
|
|
Rmq *mqs.Producer
|
|
}
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
|
sendMq := AliyunRocketMq{
|
|
AccessKey: c.ExtraConfig.Mq.AccessKey,
|
|
SecretKey: c.ExtraConfig.Mq.SecretKey,
|
|
SecurityToken: c.ExtraConfig.Mq.SecurityToken,
|
|
ServerAddress: c.ExtraConfig.Mq.Host,
|
|
}
|
|
rmq, _ := mqs.NewProducer(sendMq.ServerAddress[0], mqs.WithProducerCredentials(sendMq.AccessKey, sendMq.SecretKey, sendMq.SecurityToken))
|
|
rmq.Start()
|
|
return &ServiceContext{
|
|
Config: c,
|
|
RedisClient: redis.MustNewRedis(redis.RedisConf{
|
|
Host: c.Redis.Host,
|
|
Type: c.Redis.Type,
|
|
Pass: c.Redis.Pass,
|
|
}),
|
|
ZltxOrder: zltx.NewZltxOrder(c.ZLTX, rmq),
|
|
Market: market.NewMarket(c.Market, rmq),
|
|
RS: rs.NewRs(c.RS, rmq),
|
|
NewMarket: new_market.NewNewMarket(c.NewMarket, rmq),
|
|
Physical: physical.NewPhysical(c.Physical, rmq),
|
|
}
|
|
}
|
|
|
|
type AliyunRocketMq struct {
|
|
AccessKey string
|
|
SecretKey string
|
|
SecurityToken string
|
|
ServerAddress []string
|
|
}
|