MCPcopy Index your code
hub / github.com/mpolden/echoip / Handler

Method Handler

http/http.go:437–485  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

435}
436
437func (s *Server) Handler() http.Handler {
438 r := NewRouter()
439
440 // Health
441 r.Route("GET", "/health", s.HealthHandler)
442
443 // Health
444 r.Route("HEAD", "/", s.HeadHandler)
445
446 // JSON
447 r.Route("GET", "/", s.JSONHandler).Header("Accept", jsonMediaType)
448 r.Route("GET", "/json", s.JSONHandler)
449
450 // CLI
451 r.Route("GET", "/", s.CLIHandler).MatcherFunc(cliMatcher)
452 r.Route("GET", "/", s.CLIHandler).Header("Accept", textMediaType)
453 r.Route("GET", "/ip", s.CLIHandler)
454 if !s.gr.IsEmpty() {
455 r.Route("GET", "/country", s.CLICountryHandler)
456 r.Route("GET", "/country-iso", s.CLICountryISOHandler)
457 r.Route("GET", "/city", s.CLICityHandler)
458 r.Route("GET", "/coordinates", s.CLICoordinatesHandler)
459 r.Route("GET", "/asn", s.CLIASNHandler)
460 r.Route("GET", "/asn-org", s.CLIASNOrgHandler)
461 }
462
463 // Browser
464 if s.Template != "" {
465 r.Route("GET", "/", s.DefaultHandler)
466 }
467
468 // Port testing
469 if s.LookupPort != nil {
470 r.RoutePrefix("GET", "/port/", s.PortHandler)
471 }
472
473 // Profiling
474 if s.profile {
475 r.Route("POST", "/debug/cache/resize", s.cacheResizeHandler)
476 r.Route("GET", "/debug/cache/", s.cacheHandler)
477 r.Route("GET", "/debug/pprof/cmdline", wrapHandlerFunc(pprof.Cmdline))
478 r.Route("GET", "/debug/pprof/profile", wrapHandlerFunc(pprof.Profile))
479 r.Route("GET", "/debug/pprof/symbol", wrapHandlerFunc(pprof.Symbol))
480 r.Route("GET", "/debug/pprof/trace", wrapHandlerFunc(pprof.Trace))
481 r.RoutePrefix("GET", "/debug/pprof/", wrapHandlerFunc(pprof.Index))
482 }
483
484 return r.Handler()
485}
486
487func (s *Server) ListenAndServe(addr string) error {
488 return http.ListenAndServe(addr, s.Handler())

Callers 6

ListenAndServeMethod · 0.95
TestCLIHandlersFunction · 0.45
TestDisabledHandlersFunction · 0.45
TestJSONHandlersFunction · 0.45
TestCacheHandlerFunction · 0.45
TestCacheResizeHandlerFunction · 0.45

Calls 7

NewRouterFunction · 0.85
wrapHandlerFuncFunction · 0.85
RouteMethod · 0.80
HeaderMethod · 0.80
MatcherFuncMethod · 0.80
RoutePrefixMethod · 0.80
IsEmptyMethod · 0.65

Tested by 5

TestCLIHandlersFunction · 0.36
TestDisabledHandlersFunction · 0.36
TestJSONHandlersFunction · 0.36
TestCacheHandlerFunction · 0.36
TestCacheResizeHandlerFunction · 0.36