mirror of https://github.com/grpc/grpc-go.git
Add filenameForType
This commit is contained in:
parent
36cbb03cfe
commit
dd2c45bc03
|
@ -129,3 +129,13 @@ func (s *serverReflectionServer) nameForType(st reflect.Type) (string, error) {
|
||||||
func (s *serverReflectionServer) nameForPointer(i interface{}) (string, error) {
|
func (s *serverReflectionServer) nameForPointer(i interface{}) (string, error) {
|
||||||
return s.nameForType(reflect.TypeOf(i).Elem())
|
return s.nameForType(reflect.TypeOf(i).Elem())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *serverReflectionServer) filenameForType(st reflect.Type) (string, error) {
|
||||||
|
fd, _, err := s.fileDescForType(st)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return fd.GetName(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO filenameForMethod and Service
|
||||||
|
|
|
@ -71,3 +71,19 @@ func TestNameForPointer(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFilenameForType(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
st reflect.Type
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{reflect.TypeOf(pb.SearchResponse{}), "test.proto"},
|
||||||
|
{reflect.TypeOf(pb.SearchResponse_Result{}), "test.proto"},
|
||||||
|
} {
|
||||||
|
r, err := s.filenameForType(test.st)
|
||||||
|
t.Logf("filenameForType(%q) = %q, %v", test.st, r, err)
|
||||||
|
if err != nil || r != test.want {
|
||||||
|
t.Fatalf("filenameForType(%q) = %q, %v, want %q, <nil>", test.st, r, err, test.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue