MCPcopy
hub / github.com/grpc/grpc-go / RegisterService

Method RegisterService

server.go:770–779  ·  view source on GitHub ↗

RegisterService registers a service and its implementation to the gRPC server. It is called from the IDL generated code. This must be called before invoking Serve. If ss is non-nil (for legacy code), its type is checked to ensure it implements sd.HandlerType.

(sd *ServiceDesc, ss any)

Source from the content-addressed store, hash-verified

768// invoking Serve. If ss is non-nil (for legacy code), its type is checked to
769// ensure it implements sd.HandlerType.
770func (s *Server) RegisterService(sd *ServiceDesc, ss any) {
771 if ss != nil {
772 ht := reflect.TypeOf(sd.HandlerType).Elem()
773 st := reflect.TypeOf(ss)
774 if !st.Implements(ht) {
775 logger.Fatalf("grpc: Server.RegisterService found the handler of type %v that does not satisfy %v", st, ht)
776 }
777 }
778 s.register(sd, ss)
779}
780
781func (s *Server) register(sd *ServiceDesc, ss any) {
782 s.mu.Lock()

Callers 1

TestGetServiceInfoMethod · 0.95

Calls 2

registerMethod · 0.95
FatalfMethod · 0.65

Tested by 1

TestGetServiceInfoMethod · 0.76