func main() { config.DatabaseInit() router := InitializeRouter() // Populate database models.NewCar(&models.Car{Manufacturer: "citroen", Design: "ds3", Style: "sport", Doors: 4}) log.Fatal(http.ListenAndServe(":8080", router)) }
func CarsCreate(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-type", "application/json;charset=UTF-8") w.WriteHeader(http.StatusOK) body, err := ioutil.ReadAll(r.Body) if err != nil { log.Fatal(err) } var car models.Car err = json.Unmarshal(body, &car) if err != nil { log.Fatal(err) } models.NewCar(&car) json.NewEncoder(w).Encode(car) }