router.go 414 B

12345678910111213141516171819202122232425262728
  1. package shared
  2. import (
  3. "net/http"
  4. "github.com/go-chi/chi"
  5. )
  6. type Route struct {
  7. Endpoint *APIEndpoint
  8. Handler http.Handler
  9. }
  10. type Router struct {
  11. Router *chi.Mux
  12. Routes []*Route
  13. Config *Config
  14. }
  15. func (r *Router) RegisterRoutes() {
  16. for _, route := range r.Routes {
  17. r.Router.Method(
  18. string(route.Endpoint.Metadata.Method),
  19. route.Endpoint.Metadata.Path.RelativePath,
  20. route.Handler,
  21. )
  22. }
  23. }