Exemplo n.º 1
0
func (cr *PeopleController) Create(cx *goweb.Context) {

	// create a new appengine context
	gaerecords.CreateAppEngineContext(cx.Request)

	// create a new person
	person := People.New()

	// get the fields from the HTTP request
	var name string = cx.Request.FormValue("name")
	age, _ := strconv.Atoi64(cx.Request.FormValue("age"))

	// set the fields
	person.
		SetString("name", name).
		SetInt64("age", age)

	// save it
	err := person.Put()

	if err == nil {

		// success - redirect to see this person
		cx.RespondWithLocation(fmt.Sprint("/people/", person.ID()))

	} else {

		// failed - write the error
		cx.ResponseWriter.Write([]byte(fmt.Sprintf("Error: %v", err)))

	}

}
Exemplo n.º 2
0
func (cr *PeopleController) Delete(id string, cx *goweb.Context) {

	// create a new appengine context
	gaerecords.CreateAppEngineContext(cx.Request)

	// get the person ID from the URL
	personID, _ := strconv.Atoi64(id)

	// load the person
	person, _ := People.Find(personID)

	// delete the person
	person.Delete()

	// send them on their way
	cx.RespondWithLocation("/people")

}