Update server.go (#2021)

status-code-override
songzhibin97 3 years ago committed by chenzhihui
parent 901307e51f
commit bee818891d
  1. 48
      api/metadata/server.go

@ -63,26 +63,28 @@ func (s *Server) load() error {
} }
var err error var err error
protoregistry.GlobalFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool { protoregistry.GlobalFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool {
if fd.Services() != nil { if fd.Services() == nil {
for i := 0; i < fd.Services().Len(); i++ { return true
svc := fd.Services().Get(i) }
fdp, e := fileDescriptorProto(fd.Path()) for i := 0; i < fd.Services().Len(); i++ {
if e != nil { svc := fd.Services().Get(i)
err = e fdp, e := fileDescriptorProto(fd.Path())
return false if e != nil {
} err = e
fdps, e := allDependency(fdp) return false
if e != nil { }
err = e fdps, e := allDependency(fdp)
return false if e != nil {
} err = e
s.services[string(svc.FullName())] = &dpb.FileDescriptorSet{File: fdps} return false
if svc.Methods() != nil { }
for j := 0; j < svc.Methods().Len(); j++ { s.services[string(svc.FullName())] = &dpb.FileDescriptorSet{File: fdps}
method := svc.Methods().Get(j) if svc.Methods() == nil {
s.methods[string(svc.FullName())] = append(s.methods[string(svc.FullName())], string(method.Name())) 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 return true
@ -134,11 +136,7 @@ func parseMetadata(meta interface{}) (*dpb.FileDescriptorProto, error) {
} }
// Check if meta is the byte slice. // Check if meta is the byte slice.
if enc, ok := meta.([]byte); ok { if enc, ok := meta.([]byte); ok {
fd, err := decodeFileDesc(enc) return decodeFileDesc(enc)
if err != nil {
return nil, err
}
return fd, nil
} }
return nil, fmt.Errorf("proto not sumpport metadata: %v", meta) return nil, fmt.Errorf("proto not sumpport metadata: %v", meta)
} }

Loading…
Cancel
Save