transfer_rs/cmd/api/internal/svc/serviceContext.go

29 lines
768 B
Go
Raw Normal View History

2024-06-18 18:14:57 +08:00
package svc
import (
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/zrpc"
"rs/cmd/api/internal/config"
"rs/genModel"
"rs/rpc/transferClient"
)
type ServiceContext struct {
Config config.Config
TransferRpc transferClient.Transfer // 调用transfer服务
ProductRedirectConf genModel.ProductRedirectConfModel
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := zrpc.MustNewClient(zrpc.RpcClientConf{
Target: c.Nacos.Target,
})
sqlConn := sqlx.NewMysql(c.DB.Coupon.DataSource)
client := transferClient.NewTransfer(conn)
return &ServiceContext{
Config: c,
TransferRpc: client,
ProductRedirectConf: genModel.NewProductRedirectConfModel(sqlConn, c.Cache),
}
}