本文整理匯總了Golang中github.com/easykoo/go-blog/middleware.Context.HTML方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.HTML方法的具體用法?Golang Context.HTML怎麽用?Golang Context.HTML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/easykoo/go-blog/middleware.Context
的用法示例。
在下文中一共展示了Context.HTML方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SaveBlog
func SaveBlog(ctx *middleware.Context, blog model.Blog) {
if blog.Title == "" || blog.Content == "" {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.save.failed"))
} else {
tags := ctx.R.PostForm["tags"]
blog.SetTags(tags)
signedUser := ctx.S.Get("SignedUser").(model.User)
blog.UpdateUser = signedUser.Username
if blog.Version == 0 {
blog.State = "DRAFT"
blog.Priority = 5
blog.Author = signedUser
blog.CreateUser = signedUser.Username
err := blog.Insert()
PanicIf(err)
} else {
err := blog.Update()
PanicIf(err)
}
dbBlog, err := blog.GetBlogById()
PanicIf(err)
ctx.Set("Blog", dbBlog)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.save.success"))
}
tags, err := blog.GetAllTags()
PanicIf(err)
ctx.Set("Tags", tags)
ctx.HTML(200, "blog/edit", ctx)
}
示例2: PasswordHandler
func PasswordHandler(ctx *middleware.Context, formErr binding.Errors, password model.Password) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
if !ctx.HasError() {
if password.CurrentPassword == password.ConfirmPassword {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.password.not.changed"))
} else {
user := &model.User{Id: password.Id}
dbUser, err := user.GetUserById(user.Id)
PanicIf(err)
if dbUser.Password == Md5(password.CurrentPassword) {
dbUser.Password = Md5(password.ConfirmPassword)
err := dbUser.Update()
PanicIf(err)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
} else {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.wrong.password"))
}
}
}
default:
}
ctx.HTML(200, "profile/password", ctx)
}
示例3: PublishBlog
func PublishBlog(ctx *middleware.Context, blog model.Blog) {
switch ctx.R.Method {
case "POST":
if blog.Title == "" || blog.Content == "" {
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.publish.failed"))
} else {
tags := ctx.R.PostForm["tags"]
blog.SetTags(tags)
signedUser := ctx.S.Get("SignedUser").(model.User)
blog.State = "PUBLISHED"
blog.PublishDate = time.Now()
if blog.Version == 0 {
blog.Priority = 5
blog.Author = signedUser
blog.CreateUser = signedUser.Username
err := blog.Insert()
PanicIf(err)
} else {
err := blog.Update()
PanicIf(err)
}
}
ctx.Redirect("/blog/view/" + IntString(blog.Id))
default:
tags, err := blog.GetAllTags()
PanicIf(err)
ctx.Set("Tags", tags)
ctx.HTML(200, "blog/edit", ctx)
}
}
示例4: EditLink
func EditLink(ctx *middleware.Context, params martini.Params) {
id := params["id"]
link := new(model.Link)
link.Id = ParseInt(id)
err := link.GetLink()
PanicIf(err)
ctx.Set("Link", link)
ctx.HTML(200, "link/edit", ctx)
}
示例5: 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)
}
}
示例6: InsertLink
func InsertLink(ctx *middleware.Context, link model.Link) {
switch ctx.R.Method {
case "POST":
err := link.Insert()
PanicIf(err)
ctx.Set("success", true)
ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.send.success"))
ctx.Redirect("/link/all")
default:
ctx.HTML(200, "link/edit", ctx)
}
}
示例7: LoginHandler
func LoginHandler(ctx *middleware.Context, formErr binding.Errors, loginUser model.UserLoginForm) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
password := Md5(loginUser.Password)
user := &model.User{Username: loginUser.Username, Password: password}
if !ctx.HasError() {
if has, err := user.Exist(); has {
PanicIf(err)
if user.Locked {
ctx.Set("User", user)
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.invalid.username.or.password"))
ctx.HTML(200, "user/login", ctx)
return
}
ctx.S.Set("SignedUser", user)
Log.Info(user.Username, " login")
ctx.Redirect("/admin/dashboard")
} else {
ctx.Set("User", user)
ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.invalid.username.or.password"))
ctx.HTML(200, "user/login", ctx)
}
} else {
ctx.HTML(200, "user/login", ctx)
}
default:
ctx.HTML(200, "user/login", ctx)
}
}
示例8: EditBlog
func EditBlog(ctx *middleware.Context, params martini.Params) {
id := params["id"]
blog := new(model.Blog)
blog.Id = ParseInt(id)
err := blog.GetBlog()
PanicIf(err)
ctx.Set("Blog", blog)
tags, err := blog.GetAllTags()
PanicIf(err)
ctx.Set("Tags", tags)
ctx.HTML(200, "blog/edit", ctx)
}
示例9: SettingsHandler
func SettingsHandler(ctx *middleware.Context, settings model.Settings) {
if ctx.R.Method == "POST" {
err := settings.Update()
PanicIf(err)
dbSettings := model.GetSettings()
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
ctx.S.Set("Settings", dbSettings)
}
user := &model.User{}
users, err := user.SelectAll()
PanicIf(err)
ctx.Set("Users", users)
ctx.HTML(200, "admin/settings", ctx)
}
示例10: DashboardHandler
func DashboardHandler(ctx *middleware.Context) {
visit := new(model.Visit)
visit.SetPageActive(true)
visit.SetPageSize(10)
pageNo := ParseInt(ctx.R.FormValue("page"))
visit.SetPageNo(pageNo)
visit.AddSortProperty("create_date", "desc")
visitList, total, err := visit.SearchByPage()
PanicIf(err)
visit.SetTotalRecord(total)
visit.Result = visitList
ctx.Set("Visit", visit)
ctx.HTML(200, "admin/dashboard", ctx)
}
示例11: ProfileHandler
func ProfileHandler(ctx *middleware.Context, formErr binding.Errors, user model.User) {
switch ctx.R.Method {
case "POST":
ctx.JoinFormErrors(formErr)
if !ctx.HasError() {
err := user.Update()
PanicIf(err)
dbUser, err := user.GetUserById(user.Id)
PanicIf(err)
ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
ctx.S.Set("SignedUser", dbUser)
}
ctx.HTML(200, "profile/profile", ctx)
default:
ctx.HTML(200, "profile/profile", ctx)
}
}
示例12: 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)
}
}
示例13: AllUserHandler
func AllUserHandler(ctx *middleware.Context) {
switch ctx.R.Method {
case "POST":
user := new(model.User)
user.SetPageActive(true)
user.SetPageSize(ParseInt(ctx.R.FormValue("iDisplayLength")))
user.SetDisplayStart(ParseInt(ctx.R.FormValue("iDisplayStart")))
columnNum := ctx.R.FormValue("iSortCol_0")
sortColumn := ctx.R.FormValue("mDataProp_" + columnNum)
user.AddSortProperty(sortColumn, ctx.R.FormValue("sSortDir_0"))
users, total, err := user.SearchByPage()
PanicIf(err)
ctx.Set("aaData", users)
ctx.Set("iTotalDisplayRecords", total)
ctx.Set("iTotalRecords", total)
ctx.JSON(200, ctx.Response)
default:
ctx.HTML(200, "user/allUser", ctx)
}
}
示例14: AllBlog
func AllBlog(ctx *middleware.Context) {
switch ctx.R.Method {
case "POST":
blog := new(model.Blog)
blog.SetPageActive(true)
blog.SetPageSize(ParseInt(ctx.R.FormValue("iDisplayLength")))
blog.SetDisplayStart(ParseInt(ctx.R.FormValue("iDisplayStart")))
columnNum := ctx.R.FormValue("iSortCol_0")
sortColumn := ctx.R.FormValue("mDataProp_" + columnNum)
blog.AddSortProperty(sortColumn, ctx.R.FormValue("sSortDir_0"))
blogList, total, err := blog.SearchByPage(false)
PanicIf(err)
ctx.Set("aaData", blogList)
ctx.Set("iTotalDisplayRecords", total)
ctx.Set("iTotalRecords", total)
ctx.JSON(200, ctx.Response)
default:
ctx.HTML(200, "blog/allBlog", ctx)
}
}
示例15: Blog
func Blog(ctx *middleware.Context) {
blog := new(model.Blog)
blog.SetPageActive(true)
blog.SetPageSize(10)
pageNo := ParseInt(ctx.R.FormValue("page"))
blog.SetPageNo(pageNo)
blog.State = "PUBLISHED"
blog.AddSortProperty("publish_date", "desc")
blogList, total, err := blog.SearchByPage(true)
PanicIf(err)
blog.SetTotalRecord(total)
blog.Result = blogList
ctx.Set("Blog", blog)
tags, err := blog.GetAllTags()
PanicIf(err)
ctx.Set("Tags", tags)
ctx.HTML(200, "blog", ctx)
}