Exemplo n.º 1
0
func NewCookieSessionStore(name, secret string, defaultDuration time.Duration) CookieSessionStore {
	return CookieSessionStore{
		CookieSigner:    goanna.NewCookieSigner(secret),
		CookieName:      name,
		DefaultDuration: defaultDuration,
	}
}
Exemplo n.º 2
0
func NewSignedCookieSessionFinder(name string, key []byte, defaultDuration time.Duration, secure bool) goanna.SessionFinder {
	ss := signedCookieSessionHandler{
		CookieSigner:    goanna.NewCookieSigner(key),
		CookieName:      name,
		DefaultDuration: defaultDuration,
		Secure:          secure,
	}

	return func(r *goanna.Request) goanna.Session {
		return ss.GetSession(r)
	}
}
Exemplo n.º 3
0
func ExampleCookieSigner() {
	signer := goanna.NewCookieSigner([]byte("secret"))

	cookie := http.Cookie{
		Name:  "foo",
		Value: "bar",
	}

	fmt.Println(cookie.Value) // bar

	signer.EncodeCookie(&cookie)
	fmt.Println(cookie.Value) // aMcN2wzx4XLp9w3CPrwNb6PtTzECzkMPIiEfDqVDk4k=.bar

	signer.DecodeCookie(&cookie)
	fmt.Println(cookie.Value) // bar
}