func (this *ArticleController) Post() { article := models.NewArticle() err := this.ParseForm(article) if err != nil { this.Data["json"] = err } else { ok, err := article.Validate("create") if ok { this.Data["json"] = article } else { this.Data["json"] = err } } this.ServeJson() }
func (this *ArticleController) Get() { var id int this.Ctx.Input.Bind(&id, "id") if id <= 0 { this.Data["json"] = errors.New("User id is required") this.ServeJson() return } article := models.NewArticle() err := article.FindById(id) if err != nil { beego.Error(err) } this.Data["json"] = article this.ServeJson() }