MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / NewServeMux

Function NewServeMux

runtime/mux.go:353–380  ·  view source on GitHub ↗

NewServeMux returns a new ServeMux whose internal mapping is empty.

(opts ...ServeMuxOption)

Source from the content-addressed store, hash-verified

351
352// NewServeMux returns a new ServeMux whose internal mapping is empty.
353func NewServeMux(opts ...ServeMuxOption) *ServeMux {
354 serveMux := &ServeMux{
355 handlers: make(map[string][]handler),
356 forwardResponseOptions: make([]func(context.Context, http.ResponseWriter, proto.Message) error, 0),
357 forwardResponseRewriter: func(ctx context.Context, response proto.Message) (any, error) { return response, nil },
358 marshalers: makeMarshalerMIMERegistry(),
359 errorHandler: DefaultHTTPErrorHandler,
360 streamErrorHandler: DefaultStreamErrorHandler,
361 routingErrorHandler: DefaultRoutingErrorHandler,
362 unescapingMode: UnescapingModeDefault,
363 }
364
365 for _, opt := range opts {
366 opt(serveMux)
367 }
368
369 if serveMux.incomingHeaderMatcher == nil {
370 serveMux.incomingHeaderMatcher = DefaultHeaderMatcher
371 }
372 if serveMux.outgoingHeaderMatcher == nil {
373 serveMux.outgoingHeaderMatcher = defaultOutgoingHeaderMatcher
374 }
375 if serveMux.outgoingTrailerMatcher == nil {
376 serveMux.outgoingTrailerMatcher = defaultOutgoingTrailerMatcher
377 }
378
379 return serveMux
380}
381
382// Handle associates "h" to the pair of HTTP method and path pattern.
383func (s *ServeMux) Handle(meth string, pat Pattern, h HandlerFunc) {

Calls 1