state

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: Unlicense Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadStateFromFile added in v1.10.0

func LoadStateFromFile(
	filePath string,
	rateCache, botCache, verifiedCache *lru.Cache,
) error

LoadStateFromFile loads state from a file with locking.

func ReconcileState added in v1.10.0

func ReconcileState(fileState State, rateCache, botCache, verifiedCache *lru.Cache)

ReconcileState merges file-based state with in-memory state.

func SaveStateToFile added in v1.10.0

func SaveStateToFile(
	filePath string,
	reconcile bool,
	rateCache, botCache, verifiedCache *lru.Cache,
	log *slog.Logger,
) (lockMs, readMs, reconcileMs, marshalMs, writeMs, totalMs int64, err error)

SaveStateToFile saves state to a file with locking and optional reconciliation. When reconcile is true, it reads and merges existing file state before saving. Returns timing metrics for debugging.

func SetState added in v1.10.0

func SetState(state State, rateCache, botCache, verifiedCache *lru.Cache)

SetState loads state data into the provided caches, preserving expiration times. If an entry has already expired (expiration < now), it will be skipped.

Types

type CacheEntry added in v1.10.0

type CacheEntry struct {
	Value      interface{} `json:"value"`
	Expiration int64       `json:"expiration"` // Unix timestamp in nanoseconds, 0 means no expiration
}

CacheEntry represents a cache item with its expiration time

type FileLock added in v1.10.0

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

FileLock represents an exclusive file lock using lock file creation This implementation doesn't use syscall.Flock which is not available in Traefik plugins

func NewFileLock added in v1.10.0

func NewFileLock(path string) (*FileLock, error)

NewFileLock creates a new file lock for the given path. It uses a separate .lock file to coordinate access.

func (*FileLock) Close added in v1.10.0

func (fl *FileLock) Close() error

Close is an alias for Unlock for compatibility. It will not return an error if the lock is held by another process.

func (*FileLock) Lock added in v1.10.0

func (fl *FileLock) Lock() error

Lock acquires an exclusive lock by creating a lock file. It will retry for up to 5 seconds if the lock is held by another process.

func (*FileLock) Unlock added in v1.10.0

func (fl *FileLock) Unlock() error

Unlock releases the exclusive lock by removing the lock file This is now safer and checks the PID.

type State

type State struct {
	Rate     map[string]CacheEntry `json:"rate"`
	Bots     map[string]CacheEntry `json:"bots"`
	Verified map[string]CacheEntry `json:"verified"`
	Memory   map[string]uintptr    `json:"memory"`
}

func GetState

func GetState(rateCache, botCache, verifiedCache map[string]lru.Item) State

Jump to

Keyboard shortcuts

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