Beispiel #1
0
func postUsers(w http.ResponseWriter, r *http.Request, dbl seed.DbLayer) {
	var users []seed.User

	body := make([]byte, r.ContentLength)
	_, err := io.ReadFull(r.Body, body)
	if err != nil {
		http.Error(w, "Error reading stream.", 500)
		return
	}

	err = json.Unmarshal(body, &users)
	if err != nil {
		http.Error(w, fmt.Sprintf("Failed to parse JSON: %s", err), 500)
		return
	}

	_, err = dbl.CreateUsers(users)
	if err != nil {
		http.Error(w, fmt.Sprintf("Error creating users: ", err), 500)
		return
	}

	return
}