當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.RespondWithOK方法代碼示例

本文整理匯總了Golang中code/google/com/p/uedatakuya-goweb/goweb.Context.RespondWithOK方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.RespondWithOK方法的具體用法?Golang Context.RespondWithOK怎麽用?Golang Context.RespondWithOK使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在code/google/com/p/uedatakuya-goweb/goweb.Context的用法示例。


在下文中一共展示了Context.RespondWithOK方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

示例4: 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

示例5: 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


注:本文中的code/google/com/p/uedatakuya-goweb/goweb.Context.RespondWithOK方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。