2024-06-07 11:11:04 +08:00
|
|
|
package svc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
|
|
"trasfer_middleware/cmd/rpc/internal/config"
|
2024-06-07 14:28:29 +08:00
|
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/market"
|
2024-10-15 18:35:45 +08:00
|
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/new_market"
|
2024-11-06 17:35:59 +08:00
|
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/physical"
|
2024-06-18 16:34:14 +08:00
|
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/rs"
|
2024-06-07 11:11:04 +08:00
|
|
|
"trasfer_middleware/cmd/rpc/internal/logic/po/zltx"
|
2024-12-02 17:59:33 +08:00
|
|
|
mqs "trasfer_middleware/until/mq"
|
2024-06-07 11:11:04 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceContext struct {
|
|
|
|
Config config.Config
|
|
|
|
RedisClient *redis.Redis
|
2024-06-07 18:47:40 +08:00
|
|
|
ZltxOrder *zltx.ZltxOrder
|
|
|
|
Market *market.Market
|
2024-06-18 16:34:14 +08:00
|
|
|
RS *rs.RS
|
2024-10-15 18:35:45 +08:00
|
|
|
NewMarket *new_market.NewMarketStruct
|
2024-11-06 17:35:59 +08:00
|
|
|
Physical *physical.Physical
|
2024-12-02 17:59:33 +08:00
|
|
|
Rmq *mqs.Producer
|
2024-06-07 11:11:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
2024-12-02 17:59:33 +08:00
|
|
|
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()
|
2024-06-07 11:11:04 +08:00
|
|
|
return &ServiceContext{
|
|
|
|
Config: c,
|
|
|
|
RedisClient: redis.MustNewRedis(redis.RedisConf{
|
|
|
|
Host: c.Redis.Host,
|
|
|
|
Type: c.Redis.Type,
|
|
|
|
Pass: c.Redis.Pass,
|
|
|
|
}),
|
2024-12-02 17:59:33 +08:00
|
|
|
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),
|
2024-06-07 11:11:04 +08:00
|
|
|
}
|
|
|
|
}
|
2024-12-02 17:59:33 +08:00
|
|
|
|
|
|
|
type AliyunRocketMq struct {
|
|
|
|
AccessKey string
|
|
|
|
SecretKey string
|
|
|
|
SecurityToken string
|
|
|
|
ServerAddress []string
|
|
|
|
}
|