本文整理汇总了Golang中code/google/com/p/uedatakuya-goweb/goweb.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Options
func (cr *Controller) Options(cx *goweb.Context) {
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "PUT,DELETE,POST,GET,OPTIONS")
cx.RespondWithOK()
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:7,代码来源:controller.go
示例2: DeleteMany
func (cr *Controller) DeleteMany(cx *goweb.Context) {
log.Println("Deleting all diaries...")
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 diaries")
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.RespondWithOK()
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:13,代码来源:controller.go
示例3: Read
func (cr *Controller) Read(id string, cx *goweb.Context) {
log.Printf("Read a diary id=%s", id)
c := cr.db.C(COLLECTION)
var diary Diary
if err := c.FindId(id).One(&diary); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Read diary id=%s", id)
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.RespondWithData(diary)
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:14,代码来源:controller.go
示例4: Delete
func (cr *Controller) Delete(id string, cx *goweb.Context) {
log.Printf("Deleting a diary id=%s...", id)
c := cr.db.C(COLLECTION)
if err := c.RemoveId(id); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Deleted diary id=%s", id)
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "DELETE")
cx.RespondWithOK()
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:14,代码来源:controller.go
示例5: UpdateMany
func (cr *Controller) UpdateMany(cx *goweb.Context) {
log.Println("Update all diaries...")
c := cr.db.C(COLLECTION)
var diaries []*Diary
decoder := new(goweb.JsonRequestDecoder)
decoder.Unmarshal(cx, &diaries)
if _, err := c.UpdateAll(nil, diaries); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Println("Updated all diaries")
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.RespondWithOK()
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:18,代码来源:controller.go
示例6: Create
func (cr *Controller) Create(cx *goweb.Context) {
log.Println("Creating a diary...")
c := cr.db.C(COLLECTION)
var diary Diary
decoder := new(goweb.JsonRequestDecoder)
decoder.Unmarshal(cx, &diary)
diary.Id = bson.NewObjectId().Hex()
if err := c.Insert(&diary); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Created diary id=%s", diary.Id)
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.RespondWithData(diary.Id)
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:20,代码来源:controller.go
示例7: Update
func (cr *Controller) Update(id string, cx *goweb.Context) {
log.Printf("Update a diary id=%s...", id)
c := cr.db.C(COLLECTION)
var diary *Diary
decoder := new(goweb.JsonRequestDecoder)
decoder.Unmarshal(cx, &diary)
if err := c.UpdateId(id, diary); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Updated a diary id=%s", id)
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "PUT,DELETE,POST,GET,OPTIONS")
cx.RespondWithOK()
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:20,代码来源:controller.go
示例8: ReadMany
func (cr *Controller) ReadMany(cx *goweb.Context) {
log.Println("Read all diaries...")
c := cr.db.C(COLLECTION)
count, err := c.Count()
if err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
diaries := make([]*Diary, count)
if err := c.Find(nil).All(&diaries); err != nil {
log.Println("Error: %s", err.Error())
cx.RespondWithError(http.StatusForbidden)
return
}
log.Printf("Read all %d diaries", count)
cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
cx.RespondWithData(diaries)
}
开发者ID:tenntenn,项目名称:goweb-sample,代码行数:21,代码来源:controller.go
注:本文中的code/google/com/p/uedatakuya-goweb/goweb.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论