Documentation ¶
Index ¶
- Variables
- func Destroy(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- func FromReqContext(ctx context.Context) (*http.Request, bool)
- func FromResContext(ctx context.Context) (http.ResponseWriter, bool)
- func InitManager(opt ...Option)
- type Manager
- type ManagerStore
- type Option
- func SetCookieLifeTime(cookieLifeTime int) Option
- func SetCookieName(cookieName string) Option
- func SetDomain(domain string) Option
- func SetExpired(expired int64) Option
- func SetSecure(secure bool) Option
- func SetSessionID(sessionID func() string) Option
- func SetSign(sign []byte) Option
- func SetStore(store ManagerStore) Option
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSessionID invalid session id ErrInvalidSessionID = errors.New("invalid session id") )
Functions ¶
func FromReqContext ¶
FromReqContext returns the Request value stored in ctx, if any.
func FromResContext ¶
func FromResContext(ctx context.Context) (http.ResponseWriter, bool)
FromResContext returns the ResponseWriter value stored in ctx, if any.
func InitManager ¶
func InitManager(opt ...Option)
InitManager Initialize the global session management instance
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager A session management instance, including start and destroy operations
func NewManager ¶
NewManager Create a session management instance
type ManagerStore ¶
type ManagerStore interface { // Create a session store and specify the expiration time (in seconds) Create(ctx context.Context, sid string, expired int64) (Store, error) // Update a session store and specify the expiration time (in seconds) Update(ctx context.Context, sid string, expired int64) (Store, error) // Delete a session store Delete(ctx context.Context, sid string) error // Check the session store exists Check(ctx context.Context, sid string) (bool, error) // Close storage, release resources Close() error }
ManagerStore Management of session storage, including creation, update, and delete operations
func NewFileStore ¶
func NewFileStore(path string) ManagerStore
NewFileStore Create an instance of a file store
func NewMemoryStore ¶
func NewMemoryStore() ManagerStore
NewMemoryStore Create an instance of a memory store
type Option ¶
type Option func(*options)
Option A session parameter options
func SetCookieLifeTime ¶
SetCookieLifeTime Set the cookie expiration time (in seconds)
func SetExpired ¶
SetExpired Set session expiration time (in seconds)
func SetSessionID ¶
SetSessionID Set callback function to generate session id
type Store ¶
type Store interface { // Get a session storage context Context() context.Context // Get the current session id SessionID() string // Set session value, call save function to take effect Set(key, value string) // Get session value Get(key string) (string, bool) // Delete session value, call save function to take effect Delete(key string) string // Clear all session data, call save function to take effect Flush() // Save session data Save() error }
Store A session id storage operation