Ejemplo n.º 1
0
//测试upsert
func TestUpsert(t *testing.T) {
	body := &models.ShowWeatherModel{}
	body.CityInfo.C1 = string("101280101")
	body.Now.Temperature = string("37%")
	t.Logf("content _id:%s", body.CityInfo.C1)
	err := models.UpsertData(body)
	if err != nil {
		t.Fatalf("data save error:%s", err.Error())
	}
	result, err := models.GetOneData(string("101280101"))
	if err != nil {
		t.Fatalf("data get error:%s", err.Error())
	}
	t.Logf("content get _id:%s", result.Now.Temperature)
}
Ejemplo n.º 2
0
// @Title Get
// @Description get ShowWeatherModel by id
// @Param	id		path 	string	true		"The key for cityid"
// @Success 200 {object} models.ShowWeatherModel
// @Failure 404  not found
// @Failure 403 :id is empty
// @router /:id [get]
func (c *ShowWeatherController) GetOne() {

	cityid := c.Ctx.Input.Params[":id"]
	//fmt.Printf("cityid:%s\n", cityid)
	if cityid == "" {
		c.Ctx.Output.SetStatus(403)
		c.Data["json"] = string("is empty")
	} else {
		ob, err := models.GetOneData(cityid)
		if err != nil {
			c.Ctx.Output.SetStatus(404)
			c.Data["json"] = err.Error()
			fmt.Printf("err:%s\n", err.Error())
		} else {
			c.Data["json"] = ob
			fmt.Printf("ob:%v\n", ob)
		}
	}
	c.ServeJson()
}