You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
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)
|
|
}
|