コード例 #1
0
ファイル: signed_cookie.go プロジェクト: vinays/goodies
func NewCookieSessionStore(name, secret string, defaultDuration time.Duration) CookieSessionStore {
	return CookieSessionStore{
		CookieSigner:    goanna.NewCookieSigner(secret),
		CookieName:      name,
		DefaultDuration: defaultDuration,
	}
}
コード例 #2
0
ファイル: signed_cookie.go プロジェクト: 99designs/goodies
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)
	}
}
コード例 #3
0
ファイル: example_test.go プロジェクト: 99designs/goodies
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
}