No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 786B

12345678910111213141516171819202122232425262728293031323334
  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. //
  9. package main
  10. import (
  11. "net/http"
  12. "github.com/pressly/chi"
  13. "github.com/pressly/chi/middleware"
  14. )
  15. func main() {
  16. r := chi.NewRouter()
  17. r.Use(middleware.RequestID)
  18. r.Use(middleware.RealIP)
  19. r.Use(middleware.Logger)
  20. r.Use(middleware.Recoverer)
  21. r.Get("/", func(w http.ResponseWriter, r *http.Request) {
  22. w.Write([]byte("."))
  23. })
  24. r.Mount("/users", usersResource{}.Routes())
  25. r.Mount("/todos", todosResource{}.Routes())
  26. http.ListenAndServe(":3333", r)
  27. }