session

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextKey defines the key within the session where the middleware stores its data
	ContextKey = "session-manager"

	// 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 = env.GetOrDefault("MYSQL_DATASOURCE", "test-user:test-password@tcp(localhost)/go_om")

	// SessionCookie is the name of the session cookie used, defaults to 'session'
	SessionCookie string = env.GetOrDefault("SESSION_COOKIE", "session")
	// SessionDomain is the name of the domain associated with the session cookie
	SessionDomain string = env.GetOrDefault("SESSION_DOMAIN", "127.0.0.1")
	// SessionMaxAge is the maximum session lifetime in seconds
	SessionMaxAge int = mustParseInt(env.GetOrDefault("SESSION_MAX_AGE", "86400")) // seconds, 24 hour default
	// SessionIdleTimeout is the maximum idle time before a non-active session is discarded
	SessionIdleTimeout int = mustParseInt(env.GetOrDefault("SESSION_IDLE_TIMEOUT", "1800")) // seconds, 30 mins default
	// SessionSecure sets wether or not the cookie should be https only
	SessionSecure bool = strings.ToLower(os.Getenv("SESSION_SECURE")) == "true"
	// SessionHttpOnly sets wether the cookie be accessible via javascript
	SessionHttpOnly bool = (strings.ToLower(env.GetOrDefault("SESSION_HTTP_ONLY", "true")) == "true")
)
View Source
var (
	// 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 = false
)

Functions

func DefaultSessionMiddleware

func DefaultSessionMiddleware() (*scs.Manager, gin.HandlerFunc)

DefaultSessionMiddleware is a convenience wrapper around SessionMiddleware that creates a mysqlstore based on the environment variable MYSQL_DATASOURCE

func GetSession

func GetSession(c *gin.Context) *scs.Session

GetSession returns the session object associated with the current request context.

func SessionMiddleware

func SessionMiddleware(store scs.Store) (*scs.Manager, 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

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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