forked from fullstorydev/grpcui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.go
24 lines (21 loc) · 882 Bytes
/
files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package grpcui
import (
"github.com/jhump/protoreflect/desc"
"github.com/jhump/protoreflect/grpcreflect"
"golang.org/x/net/context"
"google.golang.org/grpc"
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
"github.com/fullstorydev/grpcurl"
)
// AllFilesViaReflection returns a slice that contains the file descriptors
// for all methods exposed by the server on the other end of the given
// connection. This returns an error if the server does not support service
// reflection. (See "google.golang.org/grpc/reflection" for more on service
// reflection.)
func AllFilesViaReflection(ctx context.Context, cc *grpc.ClientConn) ([]*desc.FileDescriptor, error) {
stub := rpb.NewServerReflectionClient(cc)
cli := grpcreflect.NewClient(ctx, stub)
cli.ListServices()
source := grpcurl.DescriptorSourceFromServer(ctx, cli)
return grpcurl.GetAllFiles(source)
}