package main import ( "net/http" "github.com/julienschmidt/httprouter" ) func (app *application) routes() http.Handler { // The httprouter package also provides a router.Handler() // method which you can use when you want to register a regular // http.Handler rather than handler functions as seen below router := httprouter.New() // Convert the notFoundResponse() helper to a http.Handler using the // http.HandlerFunc() adapter, and then set it as the custom error handler for 404 // Not Found responses. router.NotFound = http.HandlerFunc(app.notFoundResponse) // Likewise, convert the methodNotAllowedResponse() helper to a http.Handler and set // it as the custom error handler for 405 Method Not Allowed responses. router.MethodNotAllowed = http.HandlerFunc(app.methodNotAllowedResponse) router.HandlerFunc(http.MethodGet, "/v1/healthcheck", app.healthCheckHandler) router.HandlerFunc(http.MethodPost, "/v1/movies", app.createMovieHandler) router.HandlerFunc(http.MethodGet, "/v1/movies/:id", app.getMovieHandler) // middleware return app.recoverPanic(router) }