当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.SetCookie方法代码示例

本文整理汇总了Golang中github.com/astaxie/beego/context.Context.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.SetCookie方法的具体用法?Golang Context.SetCookie怎么用?Golang Context.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/astaxie/beego/context.Context的用法示例。


在下文中一共展示了Context.SetCookie方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetLoginRedirect

// get login redirect url from cookie
func GetLoginRedirect(ctx *context.Context) string {
	loginRedirect := strings.TrimSpace(ctx.GetCookie("login_to"))
	if utils.IsMatchHost(loginRedirect) == false {
		loginRedirect = "/"
	} else {
		ctx.SetCookie("login_to", "", -1, "/")
	}
	return loginRedirect
}
开发者ID:wildex,项目名称:wetalk,代码行数:10,代码来源:auth.go

示例2: giveCookie

func giveCookie(ctx *context.Context) {
	_, err := ctx.Request.Cookie("uid")
	if err != nil {
		//没有cookie
		uid := GetID()
		h := md5.New()
		h.Write([]byte(uid))
		cookie := hex.EncodeToString(h.Sum(nil))
		err = models.AddUser(uid, cookie)
		if err != nil {
			return
		}
		ctx.SetCookie("uid", cookie, 1<<31-1)
		beego.Info(cookie)

	}
	return
}
开发者ID:sllt,项目名称:ac,代码行数:18,代码来源:user.go

示例3: readFlash

// readFlash is similar to beego.ReadFromRequest except that it takes a *context.Context instead
// of a *beego.Controller, and returns a map[string]string directly instead of a Beego.FlashData
// (which only has a Data field anyway).
func readFlash(ctx *context.Context) map[string]string {
	data := map[string]string{}
	if cookie, err := ctx.Request.Cookie(beego.FlashName); err == nil {
		v, _ := url.QueryUnescape(cookie.Value)
		vals := strings.Split(v, "\x00")
		for _, v := range vals {
			if len(v) > 0 {
				kv := strings.Split(v, "\x23"+beego.FlashSeperator+"\x23")
				if len(kv) == 2 {
					data[kv[0]] = kv[1]
				}
			}
		}
		// read one time then delete it
		ctx.SetCookie(beego.FlashName, "", -1, "/")
	}
	return data
}
开发者ID:soyking,项目名称:beego-pongo2,代码行数:21,代码来源:main.go

示例4: SetLangVer

// SetLangVer sets site language version.
// It returns true when language is changed by URL parameters.
func SetLangVer(ctx *context.Context, input url.Values, data map[interface{}]interface{}) (bool, LangType) {
	isNeedRedir := false

	// 1. Check URL arguments.
	lang := input.Get("lang")

	// 2. Get language information from cookies.
	if len(lang) == 0 {
		ck, err := ctx.Request.Cookie("lang")
		if err == nil {
			lang = ck.Value
		}
	} else {
		isNeedRedir = true
	}

	// Check again in case someone modify by purpose.
	isValid := false
	for _, v := range LangTypes {
		if lang == v.Lang {
			isValid = true
			break
		}
	}
	if !isValid {
		lang = ""
		isNeedRedir = false
	}

	// 3. Get language information from 'Accept-Language'.
	if len(lang) == 0 {
		al := ctx.Request.Header.Get("Accept-Language")
		if len(al) > 2 {
			al = al[:2] // Only compare first two letters.
			for _, v := range LangTypes {
				if al == v.Lang {
					lang = al
					break
				}
			}
		}
	}

	// 4. DefaucurLang language is English.
	if len(lang) == 0 {
		lang = "en-US"
		isNeedRedir = false
	}

	curLang := LangType{
		Lang: lang,
	}

	// Save language information in cookies.
	ctx.SetCookie("lang", curLang.Lang, 1<<31-1, "/")

	restLangs := make([]*LangType, 0, len(LangTypes)-1)
	for _, v := range LangTypes {
		if lang != v.Lang {
			restLangs = append(restLangs, v)
		} else {
			curLang.Name = v.Name
		}
	}

	// Set language properties.
	data["Lang"] = curLang.Lang
	data["CurLang"] = curLang.Name
	data["RestLangs"] = restLangs

	return isNeedRedir, curLang
}
开发者ID:juju2013,项目名称:gowalker,代码行数:74,代码来源:router.go

示例5: DeleteRememberCookie

func DeleteRememberCookie(ctx *context.Context) {
	ctx.SetCookie(setting.CookieUserName, "", -1)
	ctx.SetCookie(setting.CookieRememberName, "", -1)
}
开发者ID:wildex,项目名称:wetalk,代码行数:4,代码来源:auth.go

示例6: WriteRememberCookie

func WriteRememberCookie(user *models.User, ctx *context.Context) {
	secret := utils.EncodeMd5(user.Rands + user.Password)
	days := 86400 * setting.LoginRememberDays
	ctx.SetCookie(setting.CookieUserName, user.UserName, days)
	ctx.SetSecureCookie(secret, setting.CookieRememberName, user.UserName, days)
}
开发者ID:wildex,项目名称:wetalk,代码行数:6,代码来源:auth.go

示例7: DeleteRememberCookie

func (this *BaseController) DeleteRememberCookie(ctx *context.Context) {
	ctx.SetCookie(setting.CookieUsername, "", -1)
	ctx.SetCookie(setting.CookieRememberName, "", -1)
}
开发者ID:thanzen,项目名称:identity,代码行数:4,代码来源:base.go

示例8: WriteRememberCookie

func (this *BaseController) WriteRememberCookie(u *user.User, ctx *context.Context) {
	secret := utils.EncodeMd5(u.PasswordSalt + u.Password)
	days := 86400 * setting.LoginRememberDays
	ctx.SetCookie(setting.CookieUsername, u.Username, days)
	ctx.SetSecureCookie(secret, setting.CookieRememberName, u.Username, days)
}
开发者ID:thanzen,项目名称:identity,代码行数:6,代码来源:base.go

示例9: SetCookie

func SetCookie(ctx *context.Context, username, password string, expire int) {
	ctx.SetCookie("uname", username, expire, "/")
	ctx.SetCookie("pwd", password, expire, "/")
}
开发者ID:ZhangDewei,项目名称:myblog,代码行数:4,代码来源:cookie.go


注:本文中的github.com/astaxie/beego/context.Context.SetCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。