本文整理汇总了Golang中GoWeb.Context.RespondWithLocation方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.RespondWithLocation方法的具体用法?Golang Context.RespondWithLocation怎么用?Golang Context.RespondWithLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GoWeb.Context
的用法示例。
在下文中一共展示了Context.RespondWithLocation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Create
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)))
}
}
示例2: Delete
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")
}