本文整理汇总了Golang中github.com/QLeelulu/goku.HttpContext.Redirect方法的典型用法代码示例。如果您正苦于以下问题:Golang HttpContext.Redirect方法的具体用法?Golang HttpContext.Redirect怎么用?Golang HttpContext.Redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/QLeelulu/goku.HttpContext
的用法示例。
在下文中一共展示了HttpContext.Redirect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: home_index
func home_index(ctx *goku.HttpContext) goku.ActionResulter {
u, ok := ctx.Data["user"]
if !ok || u == nil {
return ctx.Redirect("/discover")
}
user := u.(*models.User)
if user.FriendCount+user.FtopicCount < 1 {
return home_guideForNew(ctx)
}
ot := ctx.Get("o")
if ot == "" {
ot = "hot"
}
ctx.ViewData["Order"] = ot
links, _ := models.Link_ForUser(user.Id, ot, 1, golink.PAGE_SIZE) //models.Link_GetByPage(1, 20)
ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
// 最新链接的未读提醒
if ot == "hot" {
newestUnreadCount, _ := models.NewestLinkUnread_Friends(user.Id, user.LastReadFriendLinkId)
ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(user.Id, newestUnreadCount)
} else if ot == "time" && links != nil && len(links) > 0 {
models.NewestLinkUnread_UpdateForUser(user.Id, links[0].Id)
}
return ctx.View(nil)
}
示例2: link_submit
/**
* 提交一个链接并保存到数据库
*/
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {
f := forms.CreateLinkSubmitForm()
f.FillByRequest(ctx.Request)
var resubmit bool
if ctx.Get("resubmit") == "true" {
resubmit = true
}
user := ctx.Data["user"].(*models.User)
success, linkId, errorMsgs, _ := models.Link_SaveForm(f, user.Id, resubmit)
if success {
go addLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本 TODO:
return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
} else if linkId > 0 {
return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId))
} else {
ctx.ViewData["Errors"] = errorMsgs
ctx.ViewData["Values"] = f.Values()
}
return ctx.View(nil)
}
示例3: loginThirdPartyUser
func loginThirdPartyUser(u *models.ThirdPartyUser, ctx *goku.HttpContext) goku.ActionResulter {
user := u.User()
userId, email, expireInSeconds := user.Id, user.Email, 24*3600
/*if !u.TokenExpireTime.IsZero() {
utcNow := time.Now().UTC()
expireInSeconds = int(u.TokenExpireTime.Sub(utcNow) / time.Second)
}*/
setCookieForOtherPlatformUser(userId, email, expireInSeconds, ctx)
return ctx.Redirect("/")
}
示例4: OnActionExecuting
func (tf *RequireLoginFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {
if u, ok := ctx.Data["user"]; !ok || u == nil {
if ctx.IsAjax() {
ar = ctx.Json(map[string]interface{}{
"success": false,
"needLogin": true,
"errors": "请先登陆",
})
} else {
ar = ctx.Redirect("/user/login?returnurl=" + url.QueryEscape(ctx.Request.RequestURI))
}
}
return
}
示例5: home_index
func home_index(ctx *goku.HttpContext) goku.ActionResulter {
u, ok := ctx.Data["user"]
if !ok || u == nil {
return ctx.Redirect("/discover")
}
user := u.(*models.User)
ot := ctx.Get("o")
if ot == "" {
ot = "hot"
}
ctx.ViewData["Order"] = ot
links, _ := models.Link_ForUser(user.Id, ot, 1, golink.PAGE_SIZE) //models.Link_GetByPage(1, 20)
ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
return ctx.View(nil)
}
示例6: link_submit
/**
* 提交一个链接并保存到数据库
*/
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {
f := forms.CreateLinkSubmitForm()
f.FillByRequest(ctx.Request)
success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id)
if success {
return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
} else {
ctx.ViewData["Errors"] = errorMsgs
ctx.ViewData["Values"] = f.Values()
}
return ctx.View(nil)
}
示例7: link_submit
/**
* 提交一个链接并保存到数据库
*/
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {
f := forms.CreateLinkSubmitForm()
f.FillByRequest(ctx.Request)
var resubmit bool
if ctx.Get("resubmit") == "true" {
resubmit = true
}
success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id, resubmit)
if success {
return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
} else if linkId > 0 {
return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId))
} else {
ctx.ViewData["Errors"] = errorMsgs
ctx.ViewData["Values"] = f.Values()
}
return ctx.View(nil)
}
示例8: RequireLogin
func RequireLogin(ctx *goku.HttpContext) goku.ActionResulter {
if u, ok := ctx.Data["user"]; !ok || u == nil {
return ctx.Redirect("/user/login?returnurl=" + url.QueryEscape(ctx.Request.RequestURI))
}
return nil
}
示例9: Login
func (p OAuth2Provider) Login(ctx *goku.HttpContext) (actionResult goku.ActionResulter, err error) {
url := p.Config.AuthCodeURL("")
actionResult = ctx.Redirect(url)
return
}