ch4.2
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -9,7 +10,19 @@ import (
|
||||
)
|
||||
|
||||
func (app *application) createMovieHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "create a new movie")
|
||||
var input struct {
|
||||
Title string `json:"title"`
|
||||
Year int32 `json:"year"`
|
||||
Runtime int32 `json:"runtime"`
|
||||
Genres []string `json:"genres"`
|
||||
}
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&input)
|
||||
if err != nil {
|
||||
app.errorResponse(w, r, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "%+v\n", input)
|
||||
}
|
||||
|
||||
func (app *application) showMovieHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user