Some checks failed
Test / test (1.24.x, ubuntu-latest) (push) Successful in 2m56s
Test / test (1.25.x, ubuntu-latest) (push) Successful in 2m15s
Test / test (1.26.x, ubuntu-latest) (push) Successful in 2m23s
Test / test (1.27.x, ubuntu-latest) (push) Failing after 3m56s
Test / test (1.24.x, windows-latest) (push) Has been cancelled
Test / test (1.25.x, windows-latest) (push) Has been cancelled
Test / test (1.26.x, windows-latest) (push) Has been cancelled
Test / test (1.27.x, windows-latest) (push) Has been cancelled
43 lines
913 B
Go
43 lines
913 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
func main() {
|
|
r := chi.NewRouter()
|
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("root."))
|
|
})
|
|
|
|
r.Route("/road", func(r chi.Router) {
|
|
r.Get("/left", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("left road"))
|
|
})
|
|
r.Post("/right", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("right road"))
|
|
})
|
|
})
|
|
|
|
r.Put("/ping", Ping)
|
|
|
|
walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
|
|
route = strings.ReplaceAll(route, "/*/", "/")
|
|
fmt.Printf("%s %s\n", method, route)
|
|
return nil
|
|
}
|
|
|
|
if err := chi.Walk(r, walkFunc); err != nil {
|
|
fmt.Printf("Logging err: %s\n", err.Error())
|
|
}
|
|
}
|
|
|
|
// Ping returns pong
|
|
func Ping(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("pong"))
|
|
}
|