session

package
v0.0.0-...-d2171c4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: EUPL-1.2 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	UserID    int64     `json:"u"`
	Username  string    `json:"n"`
	ExpiresAt time.Time `json:"e"`
}

Data contains the session information stored in the cookie.

type FlashData

type FlashData struct {
	RecoveryCodes []string `json:"rc,omitempty"`
}

FlashData contains temporary data that is cleared after reading.

type Manager

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

Manager handles session cookie creation and parsing.

func NewManager

func NewManager(cfg *config.SessionConfig, secure bool) (*Manager, error)

NewManager creates a new session manager.

func (*Manager) Clear

func (m *Manager) Clear() *http.Cookie

Clear returns a cookie that clears the session.

func (*Manager) ClearFlash

func (m *Manager) ClearFlash() *http.Cookie

ClearFlash returns a cookie that clears the flash data.

func (*Manager) Create

func (m *Manager) Create(userID int64, username string) (*http.Cookie, error)

Create creates a new session cookie for the given user.

func (*Manager) GetFlash

func (m *Manager) GetFlash(r *http.Request) *FlashData

GetFlash reads and returns the flash data. Returns nil if no flash cookie exists.

func (*Manager) Parse

func (m *Manager) Parse(r *http.Request) (*Data, error)

Parse parses the session cookie from the request. Returns nil, nil if no valid session cookie is present.

func (*Manager) SetFlash

func (m *Manager) SetFlash(data *FlashData) (*http.Cookie, error)

SetFlash creates a flash cookie with temporary data.

Jump to

Keyboard shortcuts

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