session

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package session provides thin helpers around gin-contrib/sessions.

Index

Constants

View Source
const (
	TypeCookie = "cookie"
	TypeMemory = "memory"
	TypeRedis  = "redis"

	DefaultKey    = "sid"
	DefaultPath   = "/"
	DefaultMaxAge = 30 * 60
)

Variables

View Source
var ErrSecretRequired = errors.New("session: secret is required")

Functions

func Clear

func Clear(c *gin.Context, hooks ...Hook) error

func ClearWith

func ClearWith(c *gin.Context, opts Options, hooks ...Hook) error

func Delete

func Delete(c *gin.Context, key string, hooks ...Hook) error

func DeleteWith

func DeleteWith(c *gin.Context, key string, opts Options, hooks ...Hook) error

func Get

func Get(c *gin.Context, key string) any

func Middleware

func Middleware(cfg Config) (gin.HandlerFunc, error)

func Register

func Register(value any)

func Set

func Set(c *gin.Context, key string, value any, hooks ...Hook) error

func SetWith

func SetWith(c *gin.Context, key string, value any, opts Options, hooks ...Hook) error

Types

type Config

type Config struct {
	Type     string        `mapstructure:"type" yaml:"type"`
	Key      string        `mapstructure:"key" yaml:"key"`
	Secret   string        `mapstructure:"secret" yaml:"secret"`
	Path     string        `mapstructure:"path" yaml:"path"`
	Domain   string        `mapstructure:"domain" yaml:"domain"`
	MaxAge   int           `mapstructure:"max_age" yaml:"max_age"`
	Secure   bool          `mapstructure:"secure" yaml:"secure"`
	HTTPOnly bool          `mapstructure:"http_only" yaml:"http_only"`
	SameSite http.SameSite `mapstructure:"same_site" yaml:"same_site"`
	Redis    RedisConfig   `mapstructure:"redis" yaml:"redis"`
}

func (Config) CookieKey

func (cfg Config) CookieKey() string

func (Config) Options

func (cfg Config) Options() Options

type Hook

type Hook func(c *gin.Context, s Session, opts Options) error

type Options

type Options = sessions.Options

type RedisConfig

type RedisConfig struct {
	Network   string `mapstructure:"network" yaml:"network"`
	Address   string `mapstructure:"address" yaml:"address"`
	Host      string `mapstructure:"host" yaml:"host"`
	Port      int    `mapstructure:"port" yaml:"port"`
	Username  string `mapstructure:"username" yaml:"username"`
	Password  string `mapstructure:"password" yaml:"password"`
	DB        int    `mapstructure:"db" yaml:"db"`
	PoolSize  int    `mapstructure:"pool_size" yaml:"pool_size"`
	KeyPrefix string `mapstructure:"key_prefix" yaml:"key_prefix"`
}

type Session

type Session = sessions.Session

type Store

type Store = sessions.Store

func NewStore

func NewStore(cfg Config) (Store, error)

Jump to

Keyboard shortcuts

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