mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
session examples: add the 'AllowReclaim: true' session.Config field to true, help users like https://github.com/kataras/iris/issues/1031\#issuecomment-399894693
Former-commit-id: 2ab7e56a4fda380fb52a8912a328797ba332f2c8
This commit is contained in:
parent
d216b91074
commit
2acb6e9385
|
@ -62,7 +62,7 @@ import (
|
|||
|
||||
var (
|
||||
cookieNameForSessionID = "mycookiesessionnameid"
|
||||
sess = sessions.New(sessions.Config{Cookie: cookieNameForSessionID})
|
||||
sess = sessions.New(sessions.Config{Cookie: cookieNameForSessionID, AllowReclaim: true})
|
||||
)
|
||||
|
||||
func secret(ctx iris.Context) {
|
||||
|
|
|
@ -23,8 +23,9 @@ func main() {
|
|||
defer db.Close() // close and unlock the database if application errored.
|
||||
|
||||
sess := sessions.New(sessions.Config{
|
||||
Cookie: "sessionscookieid",
|
||||
Expires: 45 * time.Minute, // <=0 means unlimited life. Defaults to 0.
|
||||
Cookie: "sessionscookieid",
|
||||
Expires: 45 * time.Minute, // <=0 means unlimited life. Defaults to 0.
|
||||
AllowReclaim: true,
|
||||
})
|
||||
|
||||
//
|
||||
|
|
|
@ -24,8 +24,9 @@ func main() {
|
|||
defer db.Close() // close and unlock the database if application errored.
|
||||
|
||||
sess := sessions.New(sessions.Config{
|
||||
Cookie: "sessionscookieid",
|
||||
Expires: 45 * time.Minute, // <=0 means unlimited life. Defaults to 0.
|
||||
Cookie: "sessionscookieid",
|
||||
Expires: 45 * time.Minute, // <=0 means unlimited life. Defaults to 0.
|
||||
AllowReclaim: true,
|
||||
})
|
||||
|
||||
//
|
||||
|
|
|
@ -32,8 +32,10 @@ func main() {
|
|||
defer db.Close() // close the database connection if application errored.
|
||||
|
||||
sess := sessions.New(sessions.Config{
|
||||
Cookie: "sessionscookieid",
|
||||
Expires: 45 * time.Minute}, // <=0 means unlimited life. Defaults to 0.
|
||||
Cookie: "sessionscookieid",
|
||||
Expires: 45 * time.Minute, // <=0 means unlimited life. Defaults to 0.
|
||||
AllowReclaim: true,
|
||||
},
|
||||
)
|
||||
|
||||
//
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
sess := sessions.New(sessions.Config{Cookie: "myappsessionid"})
|
||||
sess := sessions.New(sessions.Config{Cookie: "myappsessionid", AllowReclaim: true})
|
||||
|
||||
app.Get("/set", func(ctx iris.Context) {
|
||||
s := sess.Start(ctx)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
var (
|
||||
cookieNameForSessionID = "mycookiesessionnameid"
|
||||
sess = sessions.New(sessions.Config{Cookie: cookieNameForSessionID})
|
||||
sess = sessions.New(sessions.Config{Cookie: cookieNameForSessionID, AllowReclaim: true})
|
||||
)
|
||||
|
||||
func secret(ctx iris.Context) {
|
||||
|
|
|
@ -24,9 +24,10 @@ func newApp() *iris.Application {
|
|||
secureCookie := securecookie.New(hashKey, blockKey)
|
||||
|
||||
mySessions := sessions.New(sessions.Config{
|
||||
Cookie: cookieName,
|
||||
Encode: secureCookie.Encode,
|
||||
Decode: secureCookie.Decode,
|
||||
Cookie: cookieName,
|
||||
Encode: secureCookie.Encode,
|
||||
Decode: secureCookie.Decode,
|
||||
AllowReclaim: true,
|
||||
})
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
|
|
|
@ -27,6 +27,13 @@ func main() {
|
|||
// of the same host, then enable it.
|
||||
// Defaults to false.
|
||||
DisableSubdomainPersistence: true,
|
||||
// AllowReclaim will allow to
|
||||
// Destroy and Start a session in the same request handler.
|
||||
// All it does is that it removes the cookie for both `Request` and `ResponseWriter` while `Destroy`
|
||||
// or add a new cookie to `Request` while `Start`.
|
||||
//
|
||||
// Defaults to false.
|
||||
AllowReclaim: true,
|
||||
})
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user