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

Method HandlePath

runtime/mux.go:392–404  ·  runtime/mux.go::ServeMux.HandlePath

HandlePath allows users to configure custom path handlers. refer: https://grpc-ecosystem.github.io/grpc-gateway/docs/operations/inject_router/

(meth string, pathPattern string, h HandlerFunc)

Source from the content-addressed store, hash-verified

390// HandlePath allows users to configure custom path handlers.
391// refer: https://grpc-ecosystem.github.io/grpc-gateway/docs/operations/inject_router/
392func (s *ServeMux) HandlePath(meth string, pathPattern string, h HandlerFunc) error {
393 compiler, err := httprule.Parse(pathPattern)
394 if err != nil {
395 return fmt.Errorf("parsing path pattern: %w", err)
396 }
397 tp := compiler.Compile()
398 pattern, err := NewPattern(tp.Version, tp.OpCodes, tp.Pool, tp.Verb)
399 if err != nil {
400 return fmt.Errorf("creating new pattern: %w", err)
401 }
402 s.Handle(meth, pattern, h)
403 return nil
404}
405
406// ServeHTTP dispatches the request to the first handler whose pattern matches to r.Method and r.URL.Path.
407func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {

Callers 4

TestServeMux_HandlePathFunction · 0.95
WithHealthEndpointAtFunction · 0.80

Calls 4

HandleMethod · 0.95
ParseFunction · 0.92
NewPatternFunction · 0.85
CompileMethod · 0.65

Tested by 3

TestServeMux_HandlePathFunction · 0.76