예제 #1
0
// @Title Post
// @Description post new WarDataModel by TeamA TeamB
// @Param	TeamA		form 	string	true		"new war TeamA"
// @Param	TeamB		form 	string	true		"new war TeamB"
// @Success 200 {string} string
// @Failure 404  not found
// @router /newwar [post]
func (c *WarDataController) NewWar() {
	wardata := models.WarDataModel{}
	if err := c.ParseForm(&wardata); err != nil {
		c.Ctx.Output.SetStatus(404)
		c.Data["json"] = err.Error()
		fmt.Printf("err:%s\n", err.Error())
	}
	fmt.Printf("teama:%s\n", wardata.TeamA)
	fmt.Printf("teamb:%s\n", wardata.TeamB)
	if wardata.TeamA == "" || wardata.TeamB == "" {
		c.Ctx.Output.SetStatus(404)
		c.Data["json"] = string("someteam empty")
	} else {
		id, err := models.AddWarData(wardata.TeamA, wardata.TeamB, 25)
		if err != nil {
			c.Ctx.Output.SetStatus(404)
			c.Data["json"] = err.Error()
			fmt.Printf("err:%s\n", err.Error())
		} else {
			c.Data["json"] = id
			fmt.Printf("id:%s\n", id)
		}
	}
	c.ServeJson()
}
예제 #2
0
func (this *NewwarHandler) handle(text []string) (result string, err error) {
	//fmt.Printf("len text:%d\n", len(text))
	if len(text) < 3 {
		err = errors.New("i need more info\n" + this.getHelp())
		return
	}
	cout, err := strconv.Atoi(text[1])
	if err != nil || cout < 0 {
		err = errors.New("arg2 must be number\n" + this.getHelp())
		return
	}
	groupname := mainhandler.getGroupName()
	if groupname == "" {
		err = errors.New("group not found groupid:" + mainhandler.rec.Group_id)
		return
	}
	enemyname := strings.Join(text[2:len(text)], " ")
	id, err := models.AddWarData(groupname, enemyname, cout)
	if err != nil {
		fmt.Println(err.Error())
		err = errors.New("server error")
	} else {
		content, err := models.GetWarData(id)
		if err == nil {
			fmt.Printf("now time:%v\n", time.Now())
			fmt.Printf("default time:%v\n", content.Begintime)
			result = printWarData(content)
		}
	}

	return

}