package main import ( "fmt" "net/http" "strconv" "github.com/julienschmidt/httprouter" ) func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusAccepted) fmt.Fprintln(w, "Resource created") } func (app *application) getMovieHandler(w http.ResponseWriter, r *http.Request) { // When httprouter is parsing a request, any interpolated URL parameters will be // stored in the request context. We can use the ParamsFromContext() function to // retrieve a slice containing these parameter names and values. params := httprouter.ParamsFromContext(r.Context()) id, err := strconv.ParseInt(params.ByName("id"), 10, 64) if err != nil || id < 1 { http.NotFound(w, r) return } app.logger.Debug((fmt.Sprintf("Using id: %d", id))) w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "show the details of movie %d\n", id) } func (app *application) healthCheckHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "status: available!") fmt.Fprintf(w, "environment: %s\n", app.config.env) fmt.Fprintf(w, "version: %s\n", Version) }