From bee818891de277bade33654a7443e1796641e2c7 Mon Sep 17 00:00:00 2001 From: songzhibin97 <49082129+songzhibin97@users.noreply.github.com> Date: Sun, 22 May 2022 10:01:45 +0800 Subject: [PATCH] Update server.go (#2021) --- api/metadata/server.go | 48 ++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/api/metadata/server.go b/api/metadata/server.go index 50970a137..c385066b4 100644 --- a/api/metadata/server.go +++ b/api/metadata/server.go @@ -63,26 +63,28 @@ func (s *Server) load() error { } var err error protoregistry.GlobalFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool { - if fd.Services() != nil { - for i := 0; i < fd.Services().Len(); i++ { - svc := fd.Services().Get(i) - fdp, e := fileDescriptorProto(fd.Path()) - if e != nil { - err = e - return false - } - fdps, e := allDependency(fdp) - if e != nil { - err = e - return false - } - s.services[string(svc.FullName())] = &dpb.FileDescriptorSet{File: fdps} - if svc.Methods() != nil { - for j := 0; j < svc.Methods().Len(); j++ { - method := svc.Methods().Get(j) - s.methods[string(svc.FullName())] = append(s.methods[string(svc.FullName())], string(method.Name())) - } - } + if fd.Services() == nil { + return true + } + for i := 0; i < fd.Services().Len(); i++ { + svc := fd.Services().Get(i) + fdp, e := fileDescriptorProto(fd.Path()) + if e != nil { + err = e + return false + } + fdps, e := allDependency(fdp) + if e != nil { + err = e + return false + } + s.services[string(svc.FullName())] = &dpb.FileDescriptorSet{File: fdps} + if svc.Methods() == nil { + continue + } + for j := 0; j < svc.Methods().Len(); j++ { + method := svc.Methods().Get(j) + s.methods[string(svc.FullName())] = append(s.methods[string(svc.FullName())], string(method.Name())) } } return true @@ -134,11 +136,7 @@ func parseMetadata(meta interface{}) (*dpb.FileDescriptorProto, error) { } // Check if meta is the byte slice. if enc, ok := meta.([]byte); ok { - fd, err := decodeFileDesc(enc) - if err != nil { - return nil, err - } - return fd, nil + return decodeFileDesc(enc) } return nil, fmt.Errorf("proto not sumpport metadata: %v", meta) }