mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
remove some examples learning content as they are exist on the wiki itself now
Former-commit-id: 8c69be5bf8ca21eb0e405ca5ad8431ceb1c2511e
This commit is contained in:
@@ -3,7 +3,9 @@ package sessions
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/iris-contrib/go.uuid"
|
||||
"github.com/kataras/iris/context"
|
||||
|
||||
uuid "github.com/iris-contrib/go.uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -103,10 +105,11 @@ type (
|
||||
// Defaults to infinitive/unlimited life duration(0).
|
||||
Expires time.Duration
|
||||
|
||||
// SessionIDGenerator should returns a random session id.
|
||||
// SessionIDGenerator can be set to a function which
|
||||
// return a unique session id.
|
||||
// By default we will use a uuid impl package to generate
|
||||
// that, but developers can change that with simple assignment.
|
||||
SessionIDGenerator func() string
|
||||
SessionIDGenerator func(ctx context.Context) string
|
||||
|
||||
// DisableSubdomainPersistence set it to true in order dissallow your subdomains to have access to the session cookie
|
||||
//
|
||||
@@ -123,7 +126,7 @@ func (c Config) Validate() Config {
|
||||
}
|
||||
|
||||
if c.SessionIDGenerator == nil {
|
||||
c.SessionIDGenerator = func() string {
|
||||
c.SessionIDGenerator = func(context.Context) string {
|
||||
id, _ := uuid.NewV4()
|
||||
return id.String()
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (s *Sessions) Start(ctx context.Context, cookieOptions ...context.CookieOpt
|
||||
cookieValue := s.decodeCookieValue(GetCookie(ctx, s.config.Cookie))
|
||||
|
||||
if cookieValue == "" { // cookie doesn't exists, let's generate a session and add set a cookie
|
||||
sid := s.config.SessionIDGenerator()
|
||||
sid := s.config.SessionIDGenerator(ctx)
|
||||
|
||||
sess := s.provider.Init(sid, s.config.Expires)
|
||||
sess.isNew = s.provider.db.Len(sid) == 0
|
||||
|
||||
Reference in New Issue
Block a user