rest-api-prototype/internal/app/router.go

27 lines
712 B
Go
Raw Permalink Normal View History

package app
import (
"net/http"
"git.pbiernat.dev/golang/rest-api-prototype/internal/app/handler"
"github.com/gorilla/mux"
)
func SetupRouter(env *handler.Env) *mux.Router {
r := mux.NewRouter()
r.NotFoundHandler = &handler.NotFoundHandler{}
r.MethodNotAllowedHandler = &handler.MethodNotAllowedHandler{}
r.Use(PrepareHeadersMiddleware)
r.Use(ValidateJsonBodyMiddleware) // probably not needed
r.Use(LoggingMiddleware)
hc := r.PathPrefix("/health").Subrouter()
hc.Handle("", handler.Init(env, handler.HealthCheckHandler)).Methods(http.MethodGet)
2022-03-11 18:08:03 +01:00
auth := r.PathPrefix("/auth").Subrouter()
auth.Handle("/login", handler.Init(env, handler.AuthLoginHandler)).Methods(http.MethodPost)
2022-03-11 18:08:03 +01:00
return r
}