reflection support #108

Open
opened 2022-04-08 09:43:01 +03:00 by vtolstov · 1 comment
vtolstov commented 2022-04-08 09:43:01 +03:00 (Migrated from github.com)

micro generated server must implements

type ServiceInfoProvider interface {
	GetServiceInfo() map[string]grpc.ServiceInfo
}

and

type ServiceRegistrar interface {
	// RegisterService registers a service and its implementation to the
	// concrete type implementing this interface.  It may not be called
	// once the server has started serving.
	// desc describes the service and its methods and handlers. impl is the
	// service implementation which is passed to the method handlers.
	RegisterService(desc *grpc.ServiceDesc), impl interface{})
}

protoc-gen-go-micro must generate

// Test_ServiceDesc is the grpc.ServiceDesc for Test service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Test_ServiceDesc = grpc.ServiceDesc{
        ServiceName: "helloworld.Test",
        HandlerType: (*TestServer)(nil),
        Methods: []grpc.MethodDesc{
                {
                        MethodName: "Call",
                        Handler:    _Test_Call_Handler,
                },
        },
        Streams:  []grpc.StreamDesc{},
        Metadata: "test.proto",
}

copy serverreflection.go from grpc-go and modify it for micro

https://github.com/grpc/grpc-go/blob/master/reflection/serverreflection.go

example usage


import "google.golang.org/grpc/reflection"

s := gserver.NewServer(
       server.Codec("application/grpc+proto", protocodec.NewCodec()),
       server.Address("127.0.0.1:0"),
       server.Register(r),
       server.Name("helloworld"),
     )
h := &testServer{}
if err = gpb.RegisterTestServer(s, h); err != nil {
       panic("can't register handler: "+ err.Error())
}

// Register reflection service on gRPC server.
reflection.Register(s)
micro generated server must implements ```go type ServiceInfoProvider interface { GetServiceInfo() map[string]grpc.ServiceInfo } ``` and ```go type ServiceRegistrar interface { // RegisterService registers a service and its implementation to the // concrete type implementing this interface. It may not be called // once the server has started serving. // desc describes the service and its methods and handlers. impl is the // service implementation which is passed to the method handlers. RegisterService(desc *grpc.ServiceDesc), impl interface{}) } ``` protoc-gen-go-micro must generate ```go // Test_ServiceDesc is the grpc.ServiceDesc for Test service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) var Test_ServiceDesc = grpc.ServiceDesc{ ServiceName: "helloworld.Test", HandlerType: (*TestServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Call", Handler: _Test_Call_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "test.proto", } ``` copy serverreflection.go from grpc-go and modify it for micro ``` https://github.com/grpc/grpc-go/blob/master/reflection/serverreflection.go ``` example usage ```go import "google.golang.org/grpc/reflection" s := gserver.NewServer( server.Codec("application/grpc+proto", protocodec.NewCodec()), server.Address("127.0.0.1:0"), server.Register(r), server.Name("helloworld"), ) h := &testServer{} if err = gpb.RegisterTestServer(s, h); err != nil { panic("can't register handler: "+ err.Error()) } // Register reflection service on gRPC server. reflection.Register(s) ```
vtolstov self-assigned this 2024-02-25 16:04:14 +03:00
https://github.com/bufbuild/connect-grpcreflect-go/blob/main/grpcreflect.go#L222
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: unistack-org/micro-server-grpc#108
No description provided.