实现 rpc 调用
This commit is contained in:
parent
bda2501bae
commit
82480c4611
@ -2,7 +2,12 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/cloudwego/kitex/client"
|
||||||
|
consul "github.com/kitex-contrib/registry-consul"
|
||||||
auth "github.com/suyiiyii/hertz101/app/auth/kitex_gen/auth"
|
auth "github.com/suyiiyii/hertz101/app/auth/kitex_gen/auth"
|
||||||
|
user1 "github.com/suyiiyii/hertz101/rpc_gen/kitex_gen/user"
|
||||||
|
"github.com/suyiiyii/hertz101/rpc_gen/rpc/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VerifyTokenByRPCService struct {
|
type VerifyTokenByRPCService struct {
|
||||||
@ -15,6 +20,19 @@ func NewVerifyTokenByRPCService(ctx context.Context) *VerifyTokenByRPCService {
|
|||||||
// Run create note info
|
// Run create note info
|
||||||
func (s *VerifyTokenByRPCService) Run(req *auth.VerifyTokenReq) (resp *auth.VerifyResp, err error) {
|
func (s *VerifyTokenByRPCService) Run(req *auth.VerifyTokenReq) (resp *auth.VerifyResp, err error) {
|
||||||
// Finish your business logic.
|
// Finish your business logic.
|
||||||
|
r, err := consul.NewConsulResolver("10.21.22.53:8500")
|
||||||
|
rpcClient, err := user.NewRPCClient("user", client.WithResolver(r))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
loginResp, err := rpcClient.Login(s.ctx, &user1.LoginReq{
|
||||||
|
Email: "11",
|
||||||
|
Password: "22",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Println(loginResp)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user