1// 2// Todos Resource 3// ============== 4// This example demonstrates a project structure that defines a subrouter and its 5// handlers on a struct, and mounting them as subrouters to a parent router. 6// See also _examples/rest for an in-depth example of a REST service, and apply 7// those same patterns to this structure. 8// 9package main 10 11import ( 12 "net/http" 13 14 "github.com/go-chi/chi/v5" 15 "github.com/go-chi/chi/v5/middleware" 16) 17 18func main() { 19 r := chi.NewRouter() 20 21 r.Use(middleware.RequestID) 22 r.Use(middleware.RealIP) 23 r.Use(middleware.Logger) 24 r.Use(middleware.Recoverer) 25 26 r.Get("/", func(w http.ResponseWriter, r *http.Request) { 27 w.Write([]byte(".")) 28 }) 29 30 r.Mount("/users", usersResource{}.Routes()) 31 r.Mount("/todos", todosResource{}.Routes()) 32 33 http.ListenAndServe(":3333", r) 34} 35