loadServices registers services and their methods from "targetFile" to "r". It must be called after loadFile is called for all files so that loadServices can resolve names of message types and their fields.
(file *File)
| 16 | // It must be called after loadFile is called for all files so that loadServices |
| 17 | // can resolve names of message types and their fields. |
| 18 | func (r *Registry) loadServices(file *File) error { |
| 19 | if grpclog.V(1) { |
| 20 | grpclog.Infof("Loading services from %s", file.GetName()) |
| 21 | } |
| 22 | var svcs []*Service |
| 23 | for _, sd := range file.GetService() { |
| 24 | if grpclog.V(2) { |
| 25 | grpclog.Infof("Registering %s", sd.GetName()) |
| 26 | } |
| 27 | svc := &Service{ |
| 28 | File: file, |
| 29 | ServiceDescriptorProto: sd, |
| 30 | ForcePrefixedName: r.standalone, |
| 31 | } |
| 32 | for _, md := range sd.GetMethod() { |
| 33 | if grpclog.V(2) { |
| 34 | grpclog.Infof("Processing %s.%s", sd.GetName(), md.GetName()) |
| 35 | } |
| 36 | opts, err := extractAPIOptions(md) |
| 37 | if err != nil { |
| 38 | grpclog.Errorf("Failed to extract HttpRule from %s.%s: %v", svc.GetName(), md.GetName(), err) |
| 39 | return err |
| 40 | } |
| 41 | optsList := r.LookupExternalHTTPRules((&Method{Service: svc, MethodDescriptorProto: md}).FQMN()) |
| 42 | if opts != nil { |
| 43 | optsList = append(optsList, opts) |
| 44 | } |
| 45 | if len(optsList) == 0 { |
| 46 | if r.generateUnboundMethods { |
| 47 | defaultOpts, err := defaultAPIOptions(svc, md) |
| 48 | if err != nil { |
| 49 | grpclog.Errorf("Failed to generate default HttpRule from %s.%s: %v", svc.GetName(), md.GetName(), err) |
| 50 | return err |
| 51 | } |
| 52 | optsList = append(optsList, defaultOpts) |
| 53 | } else { |
| 54 | if grpclog.V(1) { |
| 55 | logFn := grpclog.Infof |
| 56 | if r.warnOnUnboundMethods { |
| 57 | logFn = grpclog.Warningf |
| 58 | } |
| 59 | logFn("No HttpRule found for method: %s.%s", svc.GetName(), md.GetName()) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | meth, err := r.newMethod(svc, md, optsList) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | svc.Methods = append(svc.Methods, meth) |
| 68 | r.meths[meth.FQMN()] = meth |
| 69 | } |
| 70 | if len(svc.Methods) == 0 { |
| 71 | continue |
| 72 | } |
| 73 | if grpclog.V(2) { |
| 74 | grpclog.Infof("Registered %s with %d method(s)", svc.GetName(), len(svc.Methods)) |
| 75 | } |