session

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

session

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

Installation

go get crdx.org/session

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 added in v1.1.0

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

Delete deletes a value from the session.

func Destroy added in v1.1.0

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 added in v1.2.0

func GetID(c *fiber.Ctx) string

GetID returns the session ID.

func GetInt

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

GetInt fetches an int 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) int

GetIntOnce fetches an int 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 added in v1.1.0

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

GetUint fetches a uint 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 added in v1.1.0

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

GetUintOnce fetches an int 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, dbConfig *db.Config)

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 SetErrorHandler

func SetErrorHandler(f func(err error))

SetErrorHandler sets a function to be called if any session operations fail. Set to nil to use the default (panic).

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