session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxCookieSize = 4000
)

Variables

View Source
var (
	ErrSealedTooLarge = errors.New("coyote/session: sealed session exceeds the cookie size limit")
	ErrSealedInvalid  = errors.New("coyote/session: sealed session is missing, forged or expired")
)
View Source
var ErrNoSession = errors.New("coyote/session: no session in request context")
View Source
var ErrNoSessionID = errors.New("coyote/session: refusing to store a session with no id")

Functions

func DecodeValues

func DecodeValues(raw []byte) (map[string]any, error)

func EncodeValues

func EncodeValues(values map[string]any) ([]byte, error)

func RegisterValue

func RegisterValue(value any)

Types

type Flash

type Flash struct {
	Kind    string
	Message string
}

type ManageableStore

type ManageableStore interface {
	Store
	Count(ctx context.Context) (int, error)
	All(ctx context.Context) ([]*Session, error)
	DeleteByUserID(ctx context.Context, userID string) (int, error)
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(opts Options) *Manager

func (*Manager) CSRFToken

func (m *Manager) CSRFToken(r *http.Request) string

func (*Manager) CookieName

func (m *Manager) CookieName() string

func (*Manager) Destroy

func (m *Manager) Destroy(r *http.Request) error

func (*Manager) Lifetime

func (m *Manager) Lifetime() time.Duration

func (*Manager) Middleware

func (m *Manager) Middleware(next http.Handler) http.Handler

func (*Manager) Renew

func (m *Manager) Renew(r *http.Request) error

func (*Manager) Stateless

func (m *Manager) Stateless() bool

func (*Manager) Store

func (m *Manager) Store() Store

func (*Manager) Token

func (m *Manager) Token(r *http.Request) Token

func (*Manager) ValidCSRF

func (m *Manager) ValidCSRF(r *http.Request, candidate string) bool

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

func NewMemoryStore

func NewMemoryStore(gcInterval time.Duration) *MemoryStore

func (*MemoryStore) All

func (m *MemoryStore) All(_ context.Context) ([]*Session, error)

func (*MemoryStore) Close

func (m *MemoryStore) Close()

func (*MemoryStore) Count

func (m *MemoryStore) Count(_ context.Context) (int, error)

func (*MemoryStore) Delete

func (m *MemoryStore) Delete(_ context.Context, id string) error

func (*MemoryStore) DeleteByUserID

func (m *MemoryStore) DeleteByUserID(_ context.Context, userID string) (int, error)

func (*MemoryStore) Load

func (m *MemoryStore) Load(ctx context.Context, id string) (*Session, bool)

func (*MemoryStore) Save

func (m *MemoryStore) Save(_ context.Context, s *Session) error

type Options

type Options struct {
	Store      Store
	Sealer     *Sealer
	CookieName string
	Lifetime   time.Duration
	Rolling    bool
	Secure     bool
	HTTPOnly   bool
	SameSite   http.SameSite
	Path       string
	Domain     string
	OnError    func(error)
}

type Record

type Record struct {
	ID        string `gorm:"primaryKey;size:64"`
	UserID    string `gorm:"index;size:64"`
	Data      []byte
	CreatedAt time.Time
	ExpiresAt time.Time `gorm:"index"`
}

func RecordOf

func RecordOf(s *Session) (Record, error)

func (Record) Session

func (r Record) Session() (*Session, error)

func (Record) TableName

func (Record) TableName() string

type Sealer

type Sealer struct {
	// contains filtered or unexported fields
}

func NewSealer

func NewSealer(secret string) (*Sealer, error)

func (*Sealer) Open

func (s *Sealer) Open(value string) ([]byte, error)

func (*Sealer) Seal

func (s *Sealer) Seal(payload []byte) (string, error)

type Session

type Session struct {
	// contains filtered or unexported fields
}

func From

func From(ctx context.Context) *Session

func FromRequest

func FromRequest(r *http.Request) *Session

func Restore

func Restore(id string, values map[string]any, created, expires time.Time) *Session

func (*Session) AddFlash

func (s *Session) AddFlash(kind, message string)

func (*Session) Clear

func (s *Session) Clear()

func (*Session) ClearUser

func (s *Session) ClearUser()

func (*Session) CreatedAt

func (s *Session) CreatedAt() time.Time

func (*Session) Delete

func (s *Session) Delete(key string)

func (*Session) Destroy

func (s *Session) Destroy()

func (*Session) Destroyed

func (s *Session) Destroyed() bool

func (*Session) Expired

func (s *Session) Expired() bool

func (*Session) ExpiresAt

func (s *Session) ExpiresAt() time.Time

func (*Session) Flashes

func (s *Session) Flashes() []Flash

func (*Session) Get

func (s *Session) Get(key string) any

func (*Session) GetBool

func (s *Session) GetBool(key string) bool

func (*Session) GetInt

func (s *Session) GetInt(key string) int

func (*Session) GetString

func (s *Session) GetString(key string) string

func (*Session) ID

func (s *Session) ID() string

func (*Session) Keys

func (s *Session) Keys() []string

func (*Session) Modified

func (s *Session) Modified() bool

func (*Session) Pop

func (s *Session) Pop(key string) any

func (*Session) Set

func (s *Session) Set(key string, value any)

func (*Session) SetUserID

func (s *Session) SetUserID(id string)

func (*Session) UserID

func (s *Session) UserID() string

func (*Session) Values

func (s *Session) Values() map[string]any

type Store

type Store interface {
	Load(ctx context.Context, id string) (*Session, bool)
	Save(ctx context.Context, s *Session) error
	Delete(ctx context.Context, id string) error
}

type Token

type Token struct {
	// contains filtered or unexported fields
}

func (Token) MarshalJSON

func (t Token) MarshalJSON() ([]byte, error)

func (Token) Minted

func (t Token) Minted() string

func (Token) String

func (t Token) String() string

Jump to

Keyboard shortcuts

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