session

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SESSION                = "__session__"
	HEADER_XSESSION        = "X-Session"
	HEADER_XSESSION_EXPIRY = "X-Session-Expiry"
)

SESSION is the key which this middleware uses to store it's data in a gin.Context map

Variables

This section is empty.

Functions

func DefaultSessionMiddleware

func DefaultSessionMiddleware() gin.HandlerFunc

DefaultSessionMiddleware is a convenience wrapper around SessionMiddleware that creates a mysqlstore based version of it with parameters drawn from env, json or yaml config - refer to variables.go for details

func From added in v1.1.0

func From(c *gin.Context) context.Context

func LoadConfig added in v1.1.0

func LoadConfig(filepaths ...string)

func SessionMiddleware

func SessionMiddleware(sessionManager *scs.SessionManager, handlePanic bool) gin.HandlerFunc

SessionMiddleware creates a session middleware wrapper using scs.Manager with the provided scs.Store as the backing session storage. The return values include the manager, useful for further customization and the produced handler function for inclusion in your handler chain via gin.Use(handler)

Types

type SessionConfig added in v1.1.0

type SessionConfig struct {
	// HandlePanic indicates whether or not the session middleware will handle
	// its own panics or not. Default is false. Setting it to true will result
	// in the same behavior as using gin.Use(Logging(), Recovery()) from this
	// repository.
	HandlePanic bool

	// MySqlDataSource is the parameter used for creation of the store when calling DefaultSessionMiddleware().
	// See mysqlstore in scs for info on the required table schema.
	MySqlDataSource string
	MySqlTableName  string

	// CookieName is the name of the session cookie used, defaults to 'session'
	CookieName string
	// CookieDomain is the name of the domain associated with the session cookie
	CookieDomain string
	// SessionDomain is the name of the domain associated with the session cookie
	CookiePath string
	// {true,false}: Is the cookie HTTPS only? [default=false]
	CookieSecure bool
	// {true,false}: Shall the cookie be restricted to http or is it also accessible via Javascript? [default=true]
	CookieHttpOnly bool
	// {true,false}: Should the cookie persist across browser sessions? [default=true]
	CookiePersist bool

	// SessionLifetime is the maximum session lifetime in seconds
	SessionLifetime int
	// SessionIdletime is the maximum idle time before a non-active session is discarded
	SessionIdletime int
}
var (
	Configuration SessionConfig = SessionConfig{}
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL