Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
package grpc
|
||||
|
||||
//go:generate go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components='micro|grpc',debug=true,standalone=true,paths=source_relative:./gproto proto/test.proto"
|
||||
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto proto/test.proto"
|
||||
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components='micro',debug=true,standalone=true,paths=source_relative:./gproto proto/test.proto"
|
||||
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components='grpc',debug=true,standalone=true,paths=source_relative:./gproto proto/test.proto"
|
||||
|
@@ -17,7 +17,7 @@ type testClient struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func NewTestClient(name string, c client.Client) proto.TestClient {
|
||||
func NewTestClient(name string, c client.Client) TestClient {
|
||||
return &testClient{c: c, name: name}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func (c *testClient) Call(ctx context.Context, req *proto.Request, opts ...clien
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
func (c *testClient) StreamCall(ctx context.Context, opts ...client.CallOption) (proto.Test_StreamCallClient, error) {
|
||||
func (c *testClient) StreamCall(ctx context.Context, opts ...client.CallOption) (Test_StreamCallClient, error) {
|
||||
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Test.StreamCall", &proto.Request{}), opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -91,7 +91,7 @@ func (s *testClientStreamCall) Recv() (*proto.Response, error) {
|
||||
}
|
||||
|
||||
type testServer struct {
|
||||
proto.TestServer
|
||||
TestServer
|
||||
}
|
||||
|
||||
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
|
||||
@@ -141,7 +141,7 @@ func (s *testStreamCallStream) Recv() (*proto.Request, error) {
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func RegisterTestServer(s server.Server, sh proto.TestServer, opts ...server.HandlerOption) error {
|
||||
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
|
||||
type test interface {
|
||||
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
|
||||
StreamCall(ctx context.Context, stream server.Stream) error
|
||||
|
@@ -18,11 +18,10 @@ import (
|
||||
pb "go.unistack.org/micro-tests/server/grpc/proto"
|
||||
"go.unistack.org/micro/v3/broker"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/codec"
|
||||
"go.unistack.org/micro/v3/errors"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
mregister "go.unistack.org/micro/v3/register/memory"
|
||||
"go.unistack.org/micro/v3/router"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
"google.golang.org/grpc"
|
||||
@@ -39,8 +38,8 @@ type testnServer struct {
|
||||
pb.UnimplementedTestServer
|
||||
}
|
||||
|
||||
func NewServerHandlerWrapper() server.HandlerWrapper {
|
||||
return func(fn server.HandlerFunc) server.HandlerFunc {
|
||||
func NewServerHandlerWrapper() server.HookHandler {
|
||||
return func(fn server.FuncHandler) server.FuncHandler {
|
||||
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||
// fmt.Printf("wrap ctx: %#+v req: %#+v\n", ctx, req)
|
||||
return fn(ctx, req, rsp)
|
||||
@@ -62,6 +61,10 @@ func (g *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *testServer) StreamCall(ctx context.Context, stream gpb.Test_StreamCallStream) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *testnServer) Call(ctx context.Context, req *pb.Request) (*pb.Response, error) {
|
||||
_, ok := gmetadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
@@ -81,11 +84,10 @@ func (g *testnServer) Call(ctx context.Context, req *pb.Request) (*pb.Response,
|
||||
|
||||
func TestGRPCServer(t *testing.T) {
|
||||
var err error
|
||||
codec.DefaultMaxMsgSize = 8 * 1024 * 1024
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
_ = logger.DefaultLogger.Init(logger.WithLevel(logger.ErrorLevel))
|
||||
r := register.NewRegister()
|
||||
r := mregister.NewRegister()
|
||||
b := broker.NewBroker(broker.Register(r))
|
||||
s := gserver.NewServer(
|
||||
server.Codec("application/grpc+proto", protocodec.NewCodec()),
|
||||
@@ -93,8 +95,8 @@ func TestGRPCServer(t *testing.T) {
|
||||
server.Address("127.0.0.1:0"),
|
||||
server.Register(r),
|
||||
server.Name("helloworld"),
|
||||
gserver.Reflection(true),
|
||||
server.WrapHandler(NewServerHandlerWrapper()),
|
||||
// gserver.Reflection(true),
|
||||
server.Hooks(server.HookHandler(NewServerHandlerWrapper())),
|
||||
)
|
||||
// create router
|
||||
rtr := regRouter.NewRouter(router.Register(r))
|
||||
|
Reference in New Issue
Block a user