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

Function StartServer

internal/xds/clients/internal/testutils/fakeserver/server.go:121–142  ·  view source on GitHub ↗

StartServer makes a new Server and gets it to start listening on the given net.Listener. If the given net.Listener is nil, a new one is created on a local port for gRPC requests. The returned cancel function should be invoked by the caller upon completion of the test.

(lis net.Listener)

Source from the content-addressed store, hash-verified

119// local port for gRPC requests. The returned cancel function should be invoked
120// by the caller upon completion of the test.
121func StartServer(lis net.Listener) (*Server, func(), error) {
122 if lis == nil {
123 var err error
124 lis, err = net.Listen("tcp", "localhost:0")
125 if err != nil {
126 return nil, func() {}, fmt.Errorf("net.Listen() failed: %v", err)
127 }
128 }
129
130 s := NewServer(lis.Addr().String())
131 wp := &wrappedListener{
132 Listener: lis,
133 server: s,
134 }
135
136 server := grpc.NewServer()
137 v3lrsgrpc.RegisterLoadReportingServiceServer(server, s)
138 v3discoverygrpc.RegisterAggregatedDiscoveryServiceServer(server, s)
139 go server.Serve(wp)
140
141 return s, func() { server.Stop() }, nil
142}
143
144// NewServer returns a new instance of Server, set to accept requests on addr.
145// It is the responsibility of the caller to register the exported ADS and LRS

Calls 7

ServeMethod · 0.95
StopMethod · 0.95
NewServerFunction · 0.92
NewServerFunction · 0.70
ErrorfMethod · 0.65
StringMethod · 0.65
AddrMethod · 0.45