tokenstorage

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilData = errors.New("data map cannot be nil")
View Source
var ErrNotExists = errors.New("value does not exist")

Functions

This section is empty.

Types

type DataMap added in v1.24.0

type DataMap map[string]item

type InMemory

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

InMemory provides an in-memory implementation of a token storage system. It stores encrypted tokens associated with clients, supports expiration, and is safe for concurrent use.

func NewInMemory

func NewInMemory(encryptionKey string, expires time.Duration) *InMemory

NewInMemory creates a new in-memory token storage with the given encryption key and expiration duration.

func (*InMemory) Close added in v1.23.1

func (s *InMemory) Close() error

Close is a no-op for in-memory storage, but implements the interface for compatibility.

func (*InMemory) Delete

func (s *InMemory) Delete(client string) error

Delete removes the token data for a given client from storage. If the storage is empty or the client does not exist, it does nothing.

func (*InMemory) Get

func (s *InMemory) Get(client string) (string, error)

Get retrieves and decrypts the token for a given client. If the token is expired or does not exist, an error is returned.

func (*InMemory) Set

func (s *InMemory) Set(client, token string) error

Set stores an encrypted token for a given client, with an expiration time. The token is encrypted using AES before storage.

func (*InMemory) SetStorage added in v1.24.0

func (s *InMemory) SetStorage(data DataMap) error

SetStorage replaces the current storage data with the provided DataMap. This is mainly used for testing or restoring state.

type Storage

type Storage interface {
	Get(client string) (string, error)
	Close() error
	Delete(client string) error
	Set(client string, token string) error
}

Jump to

Keyboard shortcuts

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