本文整理汇总了Golang中github.com/stretchrcom/goweb/goweb.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Read
// Handle GET requests
func (cr *OtterAPIController) Read(id string, cx *goweb.Context) {
var otter Otter
// TODO rewrite using a tohva stored in the session
var err error = nil
//_, err := cr.Db.Retrieve(id, &otter)
if err != nil {
cx.RespondWithData(otter)
} else {
cx.RespondWithNotFound()
}
}
示例2: Delete
func (cr *Controller) Delete(id string, cx *goweb.Context) {
log.Printf("Deleting a article id=%s...", id)
c := cr.db.C(COLLECTION)
if err := c.RemoveId(id); err != nil {
log.Printf("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Deleted article id=%s", id)
cx.RespondWithOK()
}
示例3: Delete
// Handle DELETE requests
func (cr *OtterAPIController) Delete(id string, cx *goweb.Context) {
//var otter Otter
// TODO rewrite using a tohva stored in the session
// currentRev, err := cr.Db.Retrieve(id, &otter)
var err error = nil
if err != nil {
// cr.Db.Delete(id, currentRev)
cx.RespondWithOK()
} else {
cx.RespondWithNotFound()
}
}
示例4: DeleteMany
func (cr *Controller) DeleteMany(cx *goweb.Context) {
log.Println("Deleting all articles...")
c := cr.db.C(COLLECTION)
if _, err := c.RemoveAll(nil); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Println("Deleted all articles")
cx.RespondWithOK()
}
示例5: Read
func (cr *Controller) Read(id string, cx *goweb.Context) {
log.Printf("Read a article id=%s", id)
c := cr.db.C(COLLECTION)
var article Article
if err := c.FindId(id).One(&article); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Read article id=%s", id)
cx.RespondWithData(article)
}
示例6: Update
func (cr *Controller) Update(id string, cx *goweb.Context) {
log.Printf("Update a article id=%s...", id)
c := cr.db.C(COLLECTION)
var article *Article
decoder := new(goweb.JsonRequestDecoder)
decoder.Unmarshal(cx, &article)
if err := c.UpdateId(id, article); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Updated a article id=%s", id)
cx.RespondWithOK()
}
示例7: UpdateMany
func (cr *Controller) UpdateMany(cx *goweb.Context) {
log.Println("Update all articles...")
c := cr.db.C(COLLECTION)
var articles []*Article
decoder := new(goweb.JsonRequestDecoder)
decoder.Unmarshal(cx, &articles)
if _, err := c.UpdateAll(nil, articles); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Println("Updated all articles")
cx.RespondWithOK()
}
示例8: Create
func (cr *Controller) Create(cx *goweb.Context) {
log.Println("Creating a article...")
c := cr.db.C(COLLECTION)
var article Article
decoder := new(goweb.JsonRequestDecoder)
decoder.Unmarshal(cx, &article)
article.Id = bson.NewObjectId().Hex()
if err := c.Insert(&article); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Created diary id=%s", article.Id)
cx.RespondWithData(article)
}
示例9: Read
func (cr *TeamAPIController) Read(id string, cx *goweb.Context) {
if id == "1" {
cx.RespondWithData(TestEntity{id, "Mat", 28})
} else if id == "2" {
cx.RespondWithData(TestEntity{id, "Laurie", 27})
} else {
cx.RespondWithNotFound()
}
}
示例10: ReadMany
func (cr *Controller) ReadMany(cx *goweb.Context) {
log.Println("Read all articles...")
c := cr.db.C(COLLECTION)
count, err := c.Count()
if err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
articles := make([]*Article, count)
if err := c.Find(nil).All(&articles); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Read all %d articles", count)
cx.RespondWithData(articles)
}
示例11: Create
func (cr *CreateAPIController) Create(cx *goweb.Context) {
cx.PathParams["apikey"]
cx.RespondWithData(TestEntity{"1", "Mat", 28})
}
示例12: UpdateMany
func (cr *OtterAPIController) UpdateMany(cx *goweb.Context) {
cx.RespondWithStatus(http.StatusForbidden)
}
示例13: Delete
func (cr *TeamAPIController) Delete(id string, cx *goweb.Context) {
cx.RespondWithOK()
}
示例14: DeleteMany
func (cr *TeamAPIController) DeleteMany(cx *goweb.Context) {
cx.RespondWithStatus(http.StatusForbidden)
}
示例15: UpdateMany
func (cr *TeamAPIController) UpdateMany(cx *goweb.Context) {
cx.RespondWithData(TestEntity{"1", "Mat", 28})
}