descriptorsource.go 698 B

12345678910111213141516171819202122232425262728293031323334
  1. package internal
  2. import (
  3. "fmt"
  4. "github.com/fullstorydev/grpcurl"
  5. "github.com/jhump/protoreflect/desc"
  6. )
  7. // GetMethods returns all methods of the given grpcurl.DescriptorSource.
  8. func GetMethods(source grpcurl.DescriptorSource) ([]string, error) {
  9. svcs, err := source.ListServices()
  10. if err != nil {
  11. return nil, err
  12. }
  13. var methods []string
  14. for _, svc := range svcs {
  15. d, err := source.FindSymbol(svc)
  16. if err != nil {
  17. return nil, err
  18. }
  19. switch val := d.(type) {
  20. case *desc.ServiceDescriptor:
  21. svcMethods := val.GetMethods()
  22. for _, method := range svcMethods {
  23. methods = append(methods, fmt.Sprintf("%s/%s", svc, method.GetName()))
  24. }
  25. }
  26. }
  27. return methods, nil
  28. }