session

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: GPL-3.0 Imports: 4 Imported by: 8

README

session

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

Installation

go get crdx.org/session/v2

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, bool)

Get fetches a value from the session and casts it to T, returning the value and a boolean indicating whether the value was present in the session.

func GetID

func GetID(c *fiber.Ctx) string

GetID returns the session ID.

func GetInt

func GetInt(c *fiber.Ctx, key string) int64

GetInt fetches an int64 from the session, returning 0 if it isn't found. If you need to be able to differentiate between absence and 0, use Get.

func GetIntOnce

func GetIntOnce(c *fiber.Ctx, key string) int64

GetIntOnce fetches an int64 from the session and then deletes it from the session. If you need to be able to differentiate between absence and 0, use GetOnce.

func GetOnce

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

GetOnce fetches a value from the session and casts it to T, then deletes it from the session.

func GetOnceOrDefault

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

GetOnceOrDefault fetches a value from the session and casts it to T, returning the value or the default value for the type if it was not present in the session.

func GetOrDefault

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

GetOrDefault fetches a value from the session and casts it to T, returning the value or the default value for the type if it was not present in the session.

func GetString

func GetString(c *fiber.Ctx, key string) string

GetString fetches a string from the session, returning the empty string if it isn't found. If you need to be able to differentiate between absence and the empty string, use Get.

func GetStringOnce

func GetStringOnce(c *fiber.Ctx, key string) string

GetStringOnce fetches a string from the session and then deletes it from the session. If you need to be able to differentiate between absence and the empty string, use GetOnce.

func GetUint

func GetUint(c *fiber.Ctx, key string) uint64

GetUint fetches a uint64 from the session, returning 0 if it isn't found. If you need to be able to differentiate between absence and 0, use Get.

func GetUintOnce

func GetUintOnce(c *fiber.Ctx, key string) uint64

GetUintOnce fetches an int64 from the session and then deletes it from the session. If you need to be able to differentiate between absence and 0, use GetOnce.

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.

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.
	Expiration   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