2024-06-18 18:14:57 +08:00
|
|
|
package svc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
2024-06-19 18:05:50 +08:00
|
|
|
"github.com/zeromicro/go-zero/rest"
|
2024-06-19 18:35:10 +08:00
|
|
|
"github.com/zeromicro/go-zero/zrpc"
|
2024-06-18 18:14:57 +08:00
|
|
|
"rs/cmd/api/internal/config"
|
2024-06-19 18:05:50 +08:00
|
|
|
"rs/cmd/api/internal/types"
|
2024-06-18 18:14:57 +08:00
|
|
|
"rs/genModel"
|
2024-06-19 18:35:10 +08:00
|
|
|
"rs/rpc/transferClient"
|
2024-06-18 18:14:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceContext struct {
|
2024-06-19 18:05:50 +08:00
|
|
|
*types.BaseServiceContext
|
|
|
|
DecryptMiddleware rest.Middleware
|
2024-06-18 18:14:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
2024-06-19 18:35:10 +08:00
|
|
|
conn := zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
|
|
Target: c.Nacos.Target,
|
|
|
|
})
|
2024-06-18 18:14:57 +08:00
|
|
|
sqlConn := sqlx.NewMysql(c.DB.Coupon.DataSource)
|
2024-06-19 18:35:10 +08:00
|
|
|
client := transferClient.NewTransfer(conn)
|
2024-06-19 18:05:50 +08:00
|
|
|
|
|
|
|
base := types.BaseServiceContext{
|
2024-06-19 18:35:10 +08:00
|
|
|
Config: c,
|
|
|
|
TransferRpc: client,
|
2024-06-18 18:14:57 +08:00
|
|
|
ProductRedirectConf: genModel.NewProductRedirectConfModel(sqlConn, c.Cache),
|
2024-06-19 18:05:50 +08:00
|
|
|
Merchant: genModel.NewMerchantModel(sqlConn, c.Cache),
|
2024-06-18 18:14:57 +08:00
|
|
|
}
|
2024-06-19 18:05:50 +08:00
|
|
|
return &ServiceContext{
|
|
|
|
BaseServiceContext: &base,
|
|
|
|
//DecryptMiddleware: middleware.NewDecryptMiddleware(&base).Handle,
|
|
|
|
}
|
|
|
|
|
2024-06-18 18:14:57 +08:00
|
|
|
}
|