コード例 #1
0
func GetGoodsById(r render.Render, dbmap *gorp.DbMap, params martini.Params, res http.ResponseWriter) {
	id := params["id"]
	//get userinfo
	ginfo, err := goods.GetGoodsById(id, dbmap)
	if err != nil {
		r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
	}

	r.JSON(200, ginfo)
}
コード例 #2
0
func PutGoods(r render.Render, dbmap *gorp.DbMap, params martini.Params, res http.ResponseWriter, g GoodInfo, e binding.Errors) {
	id := params["id"]
	//get userinfo
	_, err := goods.GetGoodsById(id, dbmap)
	if err != nil {
		r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
	}

	//insert new user info to db;
	_, err = dbmap.Update(&g)
	if err != nil {
		glog.V(1).Infof("[DEBUG:] Update Goods %v fail:%v", g, err)
		r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
		return
	}

	r.JSON(200, map[string]string{"message": "SUCCESS"})
}