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

35 lines
794 B
Go

package svc
import (
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/zrpc"
_ "github.com/zeromicro/zero-contrib/zrpc/registry/nacos"
"rs/cmd/api/internal/config"
"rs/cmd/api/internal/middleware"
"rs/cmd/api/internal/types"
"rs/rpc/transferClient"
)
type ServiceContext struct {
*types.BaseServiceContext
SignMiddleware rest.Middleware
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := zrpc.MustNewClient(zrpc.RpcClientConf{
Target: c.Nacos.Target,
//Endpoints: []string{"127.0.0.1:10001"},
})
client := transferClient.NewTransfer(conn)
base := types.BaseServiceContext{
Config: c,
TransferRpc: client,
}
return &ServiceContext{
BaseServiceContext: &base,
SignMiddleware: middleware.NewSignMiddleware(&c).Handle,
}
}