當前位置: 首頁>>代碼示例>>Golang>>正文


Golang HttpContext.Redirect方法代碼示例

本文整理匯總了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)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:28,代碼來源:home.go

示例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)

}
開發者ID:hippasus,項目名稱:ohlala,代碼行數:28,代碼來源:link.go

示例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("/")
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:11,代碼來源:user_reg_login.go

示例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
}
開發者ID:polaris1119,項目名稱:ohlala,代碼行數:14,代碼來源:require_login.go

示例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)
}
開發者ID:t7er,項目名稱:ohlala,代碼行數:16,代碼來源:home.go

示例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)

}
開發者ID:arowser,項目名稱:ohlala,代碼行數:19,代碼來源:link.go

示例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)

}
開發者ID:kicool,項目名稱:ohlala,代碼行數:26,代碼來源:link.go

示例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
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:6,代碼來源:base.go

示例9: Login

func (p OAuth2Provider) Login(ctx *goku.HttpContext) (actionResult goku.ActionResulter, err error) {
	url := p.Config.AuthCodeURL("")
	actionResult = ctx.Redirect(url)
	return
}
開發者ID:cloudcache,項目名稱:ohlala,代碼行數:5,代碼來源:third_party_user.go


注:本文中的github.com/QLeelulu/goku.HttpContext.Redirect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。