session

package module
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: GPL-3.0 Imports: 6 Imported by: 8

README

session

session is a generic database-backed fiber-powered session wrapper for db.

Installation

go get crdx.org/session/v3

Usage

Check out the documentation on pkg.go.dev.

Contributions

Open an issue or send a pull request.

Licence

GPLv3.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(c fiber.Ctx, key string)

Delete deletes a value from the session.

func Destroy

func Destroy(c fiber.Ctx)

Destroy destroys the session.

func Get

func Get[T any](c fiber.Ctx, key string) T

Get fetches a value from the session as T. If the session doesn't contain a T then the zero value of T is returned.

func GetID

func GetID(c fiber.Ctx) string

GetID returns the session ID.

func GetOnce

func GetOnce[T any](c fiber.Ctx, key string) T

GetOnce fetches a value from the session as T, then deletes it. If the session doesn't contain a T then the zero value of T is returned.

func Init

func Init(sessionConfig *Config, dsn string)

Init initialises the session.

func Set

func Set[T any](c fiber.Ctx, key string, value T)

Set stores a value in the session. If T is a custom type then it may need to be registered with gob.Register first.

func TryGet added in v3.0.1

func TryGet[T any](c fiber.Ctx, key string) (T, bool)

TryGet fetches a value from the session as T, returning the value and a boolean indicating whether the value was present in the session.

func TryGetOnce added in v3.0.1

func TryGetOnce[T any](c fiber.Ctx, key string) (T, bool)

TryGetOnce fetches a value from the session as T, then deletes it from the session.

Types

type Config

type Config struct {
	Table        string        // The table to store the session data in.
	CookieSecure bool          // Whether the cookie should be HTTPS-only.
	IdleTimeout  time.Duration // How long the session cookie should last.
}

Jump to

Keyboard shortcuts

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