session

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package session provides simple in-memory session management for nftban-ui.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionNotFound = errors.New("session not found")
	ErrSessionExpired  = errors.New("session expired")
	ErrInvalidToken    = errors.New("invalid token")
)

Functions

func GenerateToken

func GenerateToken() (string, error)

GenerateToken creates a random 32-byte token

Types

type Session

type Session struct {
	Token     string    `json:"token"`
	Username  string    `json:"username"`
	Groups    []string  `json:"groups"`
	ClientIP  string    `json:"client_ip,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

Session represents an authenticated user session

func (*Session) HasGroup

func (s *Session) HasGroup(group string) bool

HasGroup checks if user belongs to a group

func (*Session) IsAdmin

func (s *Session) IsAdmin() bool

IsAdmin checks for admin privileges

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired checks if session has expired

type Store

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

Store is a simple in-memory session store

func NewStore

func NewStore(timeout time.Duration) *Store

NewStore creates a new session store

func (*Store) Cleanup

func (s *Store) Cleanup() int

Cleanup removes expired sessions (call periodically)

func (*Store) Count

func (s *Store) Count() int

Count returns number of active sessions

func (*Store) Create

func (s *Store) Create(username string, groups []string, clientIP string) (*Session, error)

Create stores a new session

func (*Store) Delete

func (s *Store) Delete(token string)

Delete removes a session

func (*Store) DeleteByUser

func (s *Store) DeleteByUser(username string) int

DeleteByUser removes all sessions for a user

func (*Store) Get

func (s *Store) Get(token string) (*Session, error)

Get retrieves a session by token

func (*Store) List

func (s *Store) List() []*Session

List returns all active sessions (for admin)

Jump to

Keyboard shortcuts

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