本文整理匯總了Golang中github.com/easykoo/go-blog/middleware.Context.Redirect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Redirect方法的具體用法?Golang Context.Redirect怎麽用?Golang Context.Redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/easykoo/go-blog/middleware.Context
的用法示例。
在下文中一共展示了Context.Redirect方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: 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)
}
}
示例3: AboutHandler
func AboutHandler(ctx *middleware.Context) {
settings := model.GetSettings()
about := ctx.R.FormValue("about")
settings.About = about
err := settings.Update()
PanicIf(err)
dbSettings := model.GetSettings()
ctx.S.Set("Settings", dbSettings)
ctx.Redirect("/about")
}
示例4: 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)
}
}
示例5: LogoutHandler
func LogoutHandler(ctx *middleware.Context) {
ctx.S.Set("SignedUser", nil)
ctx.Redirect("/index")
}