MCPcopy
hub / github.com/go-chi/chi / main

Function main

_examples/router-walk/main.go:11–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func main() {
12 r := chi.NewRouter()
13 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
14 w.Write([]byte("root."))
15 })
16
17 r.Route("/road", func(r chi.Router) {
18 r.Get("/left", func(w http.ResponseWriter, r *http.Request) {
19 w.Write([]byte("left road"))
20 })
21 r.Post("/right", func(w http.ResponseWriter, r *http.Request) {
22 w.Write([]byte("right road"))
23 })
24 })
25
26 r.Put("/ping", Ping)
27
28 walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
29 route = strings.ReplaceAll(route, "/*/", "/")
30 fmt.Printf("%s %s\n", method, route)
31 return nil
32 }
33
34 if err := chi.Walk(r, walkFunc); err != nil {
35 fmt.Printf("Logging err: %s\n", err.Error())
36 }
37}
38
39// Ping returns pong
40func Ping(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 5

GetMethod · 0.95
RouteMethod · 0.95
PostMethod · 0.95
PutMethod · 0.95
WriteMethod · 0.65

Tested by

no test coverage detected