Adding httprouter dependency to manage endpoints. Adding our routes to routes.go file facilitating endpoints management and adding POST /v1/movies and GET /v1/movies/:id endpoints. Updating main.go file removing ServeMux and add httprouter instead in app structure. Creating movies.go file to manage create and show movie endpoint.

This commit is contained in:
Maxime Delporte
2025-10-10 16:15:30 +02:00
parent 4342a8df0d
commit e0931223e4
6 changed files with 77 additions and 8 deletions

View File

@@ -57,13 +57,6 @@ func main() {
logger: logger,
}
/*
Declare a new servemux and add a /v1/healthcheck route which dispatches requests
to the healthcheckHandler method.
*/
mux := http.NewServeMux()
mux.HandleFunc("/v1/healthcheck", app.healthcheckHandler)
/*
Declare a HTTP server which listens on the port provided in the config struct,
uses the servemux we created above as the handler, has some sensible timeout
@@ -71,7 +64,7 @@ func main() {
*/
srv := &http.Server{
Addr: fmt.Sprintf(":%d", cfg.port),
Handler: mux,
Handler: app.routes(),
IdleTimeout: time.Minute,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,