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


Golang HttpContext.SetCookie方法代碼示例

本文整理匯總了Golang中github.com/QLeelulu/goku.HttpContext.SetCookie方法的典型用法代碼示例。如果您正苦於以下問題:Golang HttpContext.SetCookie方法的具體用法?Golang HttpContext.SetCookie怎麽用?Golang HttpContext.SetCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/QLeelulu/goku.HttpContext的用法示例。


在下文中一共展示了HttpContext.SetCookie方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ThirdParty_SaveThirdPartyProfileToSession

func ThirdParty_SaveThirdPartyProfileToSession(
	ctx *goku.HttpContext,
	profile *ThirdPartyUserProfile) (err error) {

	providerName := profile.ProviderName
	sessionKeyBase := thirdParty_GetSessionKeyBase(providerName, profile.Id)
	profileSessionId := ThirdParty_GetThirdPartyProfileSessionId(sessionKeyBase)
	expires := time.Now().Add(time.Duration(3600) * time.Second)

	b, _ := json.Marshal(profile)
	s := string(b)
	err = SaveItemToSession(profileSessionId, s, expires)
	if err != nil {
		return
	}

	c := &http.Cookie{
		Name:     config.ThirdPartyCookieKey,
		Value:    sessionKeyBase,
		Expires:  expires,
		Path:     "/",
		HttpOnly: true,
	}
	ctx.SetCookie(c)

	return
}
開發者ID:cloudcache,項目名稱:ohlala,代碼行數:27,代碼來源:third_party_user.go

示例2: setCookieForOtherPlatformUser

//為別的平台用戶寫cookie
func setCookieForOtherPlatformUser(userId int64, email string, seconds int, ctx *goku.HttpContext) {
	//注冊成功,寫cookie
	now := time.Now()
	h := md5.New()
	h.Write([]byte(fmt.Sprintf("%v-%v", email, now.Unix())))
	ticket := fmt.Sprintf("%x_%v", h.Sum(nil), now.Unix())
	expires := now.Add(time.Duration(seconds) * time.Second)
	redisClient := models.GetRedis()
	defer redisClient.Quit()
	err := redisClient.Set(ticket, userId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	} else {
		_, err = redisClient.Expireat(ticket, expires.Unix())
		if err != nil {
			goku.Logger().Errorln(err.Error())
		}
		c := &http.Cookie{
			Name:     "_glut",
			Value:    ticket,
			Expires:  expires,
			Path:     "/",
			HttpOnly: true,
		}
		ctx.SetCookie(c)
	}
}
開發者ID:t7er,項目名稱:ohlala,代碼行數:28,代碼來源:user_reg_login.go

示例3: thirdParty_ClearThirdPartyProfileFromSession

func thirdParty_ClearThirdPartyProfileFromSession(ctx *goku.HttpContext) {
	sessionIdBase := ctx.Data["thirdPartySessionIdBase"].(string)
	sessinId := ThirdParty_GetThirdPartyProfileSessionId(sessionIdBase)
	RemoveItemFromSession(sessinId)

	c := &http.Cookie{
		Name:    config.ThirdPartyCookieKey,
		Expires: time.Now().Add(-10 * time.Second),
		Path:    "/",
	}
	ctx.SetCookie(c)
}
開發者ID:cloudcache,項目名稱:ohlala,代碼行數:12,代碼來源:third_party_user.go

示例4: discover_index

// 發現 首頁
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE

	// 最新鏈接的未讀提醒
	var userId, lastReadLinkId int64
	unreadCookieName := "newestUnrLinkId"
	u, ok := ctx.Data["user"]
	if ok && u != nil {
		user := u.(*models.User)
		userId = user.Id
		lastReadLinkId = user.LastReadLinkId
	} else {
		// 從Cook讀取最後一次閱讀的鏈接id
		cLastReadLinkId, err := ctx.Request.Cookie(unreadCookieName)
		if err == nil {
			lastReadLinkId, _ = strconv.ParseInt(cLastReadLinkId.Value, 10, 64)
		}
	}
	if ot == "hot" {
		newestUnreadCount, _ := models.NewestLinkUnread_All(userId, lastReadLinkId)
		ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(userId, newestUnreadCount)
	} else if ot == "time" && links != nil && len(links) > 0 {
		if userId > 0 {
			models.NewestLinkUnread_UpdateForAll(userId, links[0].Id)
		} else {
			c := &http.Cookie{
				Name:     unreadCookieName,
				Value:    fmt.Sprintf("%d", links[0].Id),
				Expires:  time.Now().AddDate(0, 1, 0),
				Path:     "/",
				HttpOnly: true,
			}
			ctx.SetCookie(c)
		}
	}

	return ctx.Render("/home/index", nil)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:48,代碼來源:discover.go


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