mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
Add two examples for folder structuring as requested at https://github.com/kataras/iris/issues/748
Former-commit-id: 27c97d005d9cbd2309587b11fc9e2bab85870502
This commit is contained in:
@@ -11,12 +11,39 @@ const (
|
||||
DefaultCookieName = "irissessionid"
|
||||
)
|
||||
|
||||
// Encoding is the Cookie Encoder/Decoder interface, which can be passed as configuration field
|
||||
// alternatively to the `Encode` and `Decode` fields.
|
||||
type Encoding interface {
|
||||
// Encode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Name)
|
||||
// as second argument the server's generated session id.
|
||||
// Should return the new session id, if error the session id setted to empty which is invalid.
|
||||
//
|
||||
// Note: Errors are not printed, so you have to know what you're doing,
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
//
|
||||
// Defaults to nil
|
||||
Encode(cookieName string, value interface{}) (string, error)
|
||||
// Decode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Name)
|
||||
// as second second accepts the client's cookie value (the encoded session id).
|
||||
// Should return an error if decode operation failed.
|
||||
//
|
||||
// Note: Errors are not printed, so you have to know what you're doing,
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
//
|
||||
// Defaults to nil
|
||||
Decode(cookieName string, cookieValue string, v interface{}) error
|
||||
}
|
||||
|
||||
type (
|
||||
// Config is the configuration for sessions. Please review it well before using sessions.
|
||||
Config struct {
|
||||
// Cookie string, the session's client cookie name, for example: "mysessionid"
|
||||
//
|
||||
// Defaults to "irissessionid"
|
||||
// Defaults to "irissessionid".
|
||||
Cookie string
|
||||
|
||||
// CookieSecureTLS set to true if server is running over TLS
|
||||
@@ -26,11 +53,11 @@ type (
|
||||
// Recommendation: You don't need this to be setted to true, just fill the Encode and Decode fields
|
||||
// with a third-party library like secure cookie, example is provided at the _examples folder.
|
||||
//
|
||||
// Defaults to false
|
||||
// Defaults to false.
|
||||
CookieSecureTLS bool
|
||||
|
||||
// Encode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Name)
|
||||
// Should accept as first argument the cookie name (config.Cookie)
|
||||
// as second argument the server's generated session id.
|
||||
// Should return the new session id, if error the session id setted to empty which is invalid.
|
||||
//
|
||||
@@ -38,10 +65,10 @@ type (
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
//
|
||||
// Defaults to nil
|
||||
// Defaults to nil.
|
||||
Encode func(cookieName string, value interface{}) (string, error)
|
||||
// Decode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Name)
|
||||
// Should accept as first argument the cookie name (config.Cookie)
|
||||
// as second second accepts the client's cookie value (the encoded session id).
|
||||
// Should return an error if decode operation failed.
|
||||
//
|
||||
@@ -49,9 +76,13 @@ type (
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
//
|
||||
// Defaults to nil
|
||||
// Defaults to nil.
|
||||
Decode func(cookieName string, cookieValue string, v interface{}) error
|
||||
|
||||
// Encoding same as Encode and Decode but receives a single instance which
|
||||
// completes the "CookieEncoder" interface, `Encode` and `Decode` functions.
|
||||
Encoding Encoding
|
||||
|
||||
// Expires the duration of which the cookie must expires (created_time.Add(Expires)).
|
||||
// If you want to delete the cookie when the browser closes, set it to -1.
|
||||
//
|
||||
@@ -59,7 +90,7 @@ type (
|
||||
// -1 means when browser closes
|
||||
// > 0 is the time.Duration which the session cookies should expire.
|
||||
//
|
||||
// Defaults to infinitive/unlimited life duration(0)
|
||||
// Defaults to infinitive/unlimited life duration(0).
|
||||
Expires time.Duration
|
||||
|
||||
// SessionIDGenerator should returns a random session id.
|
||||
@@ -69,7 +100,7 @@ type (
|
||||
|
||||
// DisableSubdomainPersistence set it to true in order dissallow your subdomains to have access to the session cookie
|
||||
//
|
||||
// Defaults to false
|
||||
// Defaults to false.
|
||||
DisableSubdomainPersistence bool
|
||||
}
|
||||
)
|
||||
@@ -88,5 +119,10 @@ func (c Config) Validate() Config {
|
||||
}
|
||||
}
|
||||
|
||||
if c.Encoding != nil {
|
||||
c.Encode = c.Encoding.Encode
|
||||
c.Decode = c.Encoding.Decode
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user