本文整理匯總了Golang中github.com/easykoo/go-blog/middleware.Context.JSON方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.JSON方法的具體用法?Golang Context.JSON怎麽用?Golang Context.JSON使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/easykoo/go-blog/middleware.Context
的用法示例。
在下文中一共展示了Context.JSON方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Comment
func Comment(ctx *middleware.Context) {
id := ParseInt(ctx.R.PostFormValue("blogId"))
name := ctx.R.PostFormValue("name")
email := ctx.R.PostFormValue("email")
www := ctx.R.PostFormValue("www")
content := ctx.R.PostFormValue("content")
blog := model.Blog{Id: id}
if exist, err := blog.Exist(); exist {
PanicIf(err)
comment := model.Comment{Blog: model.Blog{Id: id}, Name: name, Email: email, Www: www, Content: content}
if comment.Content == "" {
ctx.Set("success", false)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.submit.failed"))
} else if blog.ForbidComment {
ctx.Set("success", false)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.forbid.comment"))
} else {
comment.Ip = GetRemoteIp(ctx.R)
err := comment.Insert()
PanicIf(err)
ctx.Set("success", true)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.submit.success"))
}
} else {
ctx.Set("success", false)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.blog.not.exists"))
}
ctx.JSON(200, ctx.Response)
}
示例2: ViewFeedback
func ViewFeedback(ctx *middleware.Context, params martini.Params) {
id := params["id"]
feedback := new(model.Feedback)
feedback.Id = ParseInt(id)
err := feedback.SetViewed(true)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例3: DeleteLink
func DeleteLink(ctx *middleware.Context, params martini.Params) {
id := params["id"]
link := new(model.Link)
link.Id = ParseInt(id)
err := link.Delete()
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例4: PermitBlog
func PermitBlog(ctx *middleware.Context, params martini.Params) {
id := params["id"]
blog := new(model.Blog)
blog.Id = ParseInt(id)
err := blog.Forbid(false)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例5: FeedbackInfo
func FeedbackInfo(ctx *middleware.Context) {
feedback := new(model.Feedback)
feedback.Viewed = false
feedbackArray, count, err := feedback.Info()
PanicIf(err)
ctx.Set("Array", feedbackArray)
ctx.Set("Count", count)
ctx.JSON(200, ctx.Response)
}
示例6: LiftUser
func LiftUser(ctx *middleware.Context, params martini.Params) {
id := params["id"]
user := new(model.User)
user.Id = ParseInt(id)
err := user.SetLock(false)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例7: DeleteFeedbackArray
func DeleteFeedbackArray(ctx *middleware.Context) {
feedbackArray := ctx.R.FormValue("feedbackArray")
feedback := new(model.Feedback)
var res []int
json.Unmarshal([]byte(feedbackArray), &res)
err := feedback.DeleteFeedbackArray(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例8: DeleteLinkArray
func DeleteLinkArray(ctx *middleware.Context) {
linkArray := ctx.R.FormValue("linkArray")
link := new(model.Link)
var res []int
json.Unmarshal([]byte(linkArray), &res)
err := link.DeleteLinkArray(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例9: DeleteBlogArray
func DeleteBlogArray(ctx *middleware.Context) {
blogArray := ctx.R.FormValue("blogArray")
blog := new(model.Blog)
var res []int
json.Unmarshal([]byte(blogArray), &res)
err := blog.DeleteBlogArray(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例10: DeleteUsers
func DeleteUsers(ctx *middleware.Context) {
users := ctx.R.FormValue("Users")
var res []int
json.Unmarshal([]byte(users), &res)
user := new(model.User)
err := user.DeleteUsers(res)
PanicIf(err)
ctx.Set("success", true)
ctx.JSON(200, ctx.Response)
}
示例11: CheckEmail
func CheckEmail(ctx *middleware.Context) {
if user := ctx.S.Get("SignedUser"); user.(model.User).Email != ctx.R.Form["email"][0] {
test := &model.User{Email: ctx.R.Form["email"][0]}
if exist, _ := test.ExistEmail(); exist {
ctx.JSON(200, Translate(ctx.S.Get("Lang").(string), "message.error.already.exists"))
return
}
}
ctx.JSON(200, true)
}
示例12: ContactHandler
func ContactHandler(ctx *middleware.Context, feedback model.Feedback) {
switch ctx.R.Method {
case "POST":
err := feedback.Insert()
PanicIf(err)
ctx.Set("success", true)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.send.success"))
ctx.JSON(200, ctx.Response)
default:
ctx.HTML(200, "contact", ctx)
}
}
示例13: SetRole
func SetRole(ctx *middleware.Context) {
id := ctx.R.PostFormValue("Id")
roleId := ctx.R.PostFormValue("RoleId")
version := ctx.R.PostFormValue("Version")
user := new(model.User)
user.Id = ParseInt(id)
user.Role.Id = ParseInt(roleId)
user.Version = ParseInt(version)
err := user.SetRole()
PanicIf(err)
ctx.Set("success", true)
Log.Info("User: ", user.Id, " roleId set to ", roleId)
ctx.JSON(200, ctx.Response)
}
示例14: DeleteComment
func DeleteComment(ctx *middleware.Context, params martini.Params) {
blogId := ParseInt(params["blogId"])
seq := ParseInt(params["seq"])
comment := model.Comment{Blog: model.Blog{Id: blogId}, Seq: seq}
err := comment.Delete()
if err != nil {
ctx.Set("success", false)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.delete.failed"))
} else {
ctx.Set("success", true)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.delete.success"))
}
ctx.JSON(200, ctx.Response)
}
示例15: AllFeedback
func AllFeedback(ctx *middleware.Context) {
switch ctx.R.Method {
case "POST":
feedback := new(model.Feedback)
feedback.SetPageActive(true)
feedback.SetPageSize(ParseInt(ctx.R.FormValue("iDisplayLength")))
feedback.SetDisplayStart(ParseInt(ctx.R.FormValue("iDisplayStart")))
columnNum := ctx.R.FormValue("iSortCol_0")
sortColumn := ctx.R.FormValue("mDataProp_" + columnNum)
feedback.AddSortProperty(sortColumn, ctx.R.FormValue("sSortDir_0"))
feedbackArray, total, err := feedback.SearchByPage()
PanicIf(err)
ctx.Set("aaData", feedbackArray)
ctx.Set("iTotalDisplayRecords", total)
ctx.Set("iTotalRecords", total)
ctx.JSON(200, ctx.Response)
default:
ctx.HTML(200, "feedback/allFeedback", ctx)
}
}