memory

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package memory provides in-memory implementations of outbound ports.

Package memory provides in-memory implementations of outbound ports.

Package memory provides in-memory implementations of outbound ports.

Package memory provides in-memory implementations of outbound ports.

Index

Constants

View Source
const DefaultCleanupInterval = 1 * time.Minute

Default cleanup interval for session expiration.

Variables

View Source
var (
	ErrKeyNotFound      = errors.New("api key not found")
	ErrIdentityNotFound = errors.New("identity not found")
)

Error types for auth store operations.

View Source
var (
	ErrPolicyNotFound = errors.New("policy not found")
)

Error types for policy store operations.

Functions

This section is empty.

Types

type AuthStore

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

AuthStore implements auth.AuthStore with in-memory maps. Thread-safe for concurrent access. For development/testing only.

func NewAuthStore

func NewAuthStore() *AuthStore

NewAuthStore creates a new in-memory auth store.

func (*AuthStore) AddIdentity

func (s *AuthStore) AddIdentity(identity *auth.Identity)

AddIdentity adds an identity (for testing/seeding).

func (*AuthStore) AddKey

func (s *AuthStore) AddKey(key *auth.APIKey)

AddKey adds an API key (for testing/seeding).

func (*AuthStore) GetAPIKey

func (s *AuthStore) GetAPIKey(ctx context.Context, keyHash string) (*auth.APIKey, error)

GetAPIKey retrieves an API key by its hash. Returns ErrKeyNotFound if key doesn't exist.

func (*AuthStore) GetIdentity

func (s *AuthStore) GetIdentity(ctx context.Context, id string) (*auth.Identity, error)

GetIdentity retrieves user identity by ID. Returns ErrIdentityNotFound if identity doesn't exist.

func (*AuthStore) ListAPIKeys

func (s *AuthStore) ListAPIKeys(ctx context.Context) ([]*auth.APIKey, error)

ListAPIKeys returns all stored API keys for iteration-based verification.

func (*AuthStore) RemoveKey

func (s *AuthStore) RemoveKey(keyField string)

RemoveKey removes an API key by its stored hash/key field.

type MemoryAuditStore

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

MemoryAuditStore implements audit.AuditStore writing to stdout or a file. Also keeps a bounded in-memory ring buffer for recent record queries.

func NewAuditStore

func NewAuditStore(capacity ...int) *MemoryAuditStore

NewAuditStore creates a new audit store writing to stdout. An optional capacity parameter sets the ring buffer size (default 1000).

func NewAuditStoreWithWriter

func NewAuditStoreWithWriter(w io.Writer, capacity ...int) *MemoryAuditStore

NewAuditStoreWithWriter creates an audit store writing to the given writer. An optional capacity parameter sets the ring buffer size (default 1000).

func (*MemoryAuditStore) Append

func (s *MemoryAuditStore) Append(ctx context.Context, records ...audit.AuditRecord) error

Append stores audit records by writing them as JSON to the output and keeping them in the in-memory ring buffer.

func (*MemoryAuditStore) Close

func (s *MemoryAuditStore) Close() error

Close releases resources.

func (*MemoryAuditStore) Flush

func (s *MemoryAuditStore) Flush(ctx context.Context) error

Flush forces pending records to storage. No-op for this implementation (no buffering).

func (*MemoryAuditStore) GetRecent

func (s *MemoryAuditStore) GetRecent(n int) []audit.AuditRecord

GetRecent returns the N most recent audit records (newest first).

func (*MemoryAuditStore) Query

Query retrieves audit records matching the filter from the in-memory buffer.

type MemoryPolicyStore

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

MemoryPolicyStore implements policy.PolicyStore with in-memory map. Thread-safe for concurrent access. For development/testing only.

func NewPolicyStore

func NewPolicyStore() *MemoryPolicyStore

NewPolicyStore creates a new in-memory policy store.

func (*MemoryPolicyStore) AddPolicy

func (s *MemoryPolicyStore) AddPolicy(p *policy.Policy)

AddPolicy adds a policy (for testing/seeding).

func (*MemoryPolicyStore) DeletePolicy

func (s *MemoryPolicyStore) DeletePolicy(ctx context.Context, id string) error

DeletePolicy removes a policy by ID. Returns ErrPolicyNotFound if policy doesn't exist.

func (*MemoryPolicyStore) DeleteRule

func (s *MemoryPolicyStore) DeleteRule(ctx context.Context, policyID, ruleID string) error

DeleteRule removes a rule by ID.

func (*MemoryPolicyStore) GetAllPolicies

func (s *MemoryPolicyStore) GetAllPolicies(ctx context.Context) ([]policy.Policy, error)

GetAllPolicies returns all enabled policies.

func (*MemoryPolicyStore) GetPolicy

func (s *MemoryPolicyStore) GetPolicy(ctx context.Context, id string) (*policy.Policy, error)

GetPolicy returns a policy by ID. Returns ErrPolicyNotFound if policy doesn't exist.

func (*MemoryPolicyStore) GetPolicyWithRules

func (s *MemoryPolicyStore) GetPolicyWithRules(ctx context.Context, id string) (*policy.Policy, error)

GetPolicyWithRules returns a policy with all its rules loaded. For memory store, this is the same as GetPolicy since rules are always loaded.

func (*MemoryPolicyStore) SavePolicy

func (s *MemoryPolicyStore) SavePolicy(ctx context.Context, p *policy.Policy) error

SavePolicy creates or updates a policy.

func (*MemoryPolicyStore) SaveRule

func (s *MemoryPolicyStore) SaveRule(ctx context.Context, policyID string, r *policy.Rule) error

SaveRule creates or updates a rule within a policy.

type MemoryRateLimiter

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

MemoryRateLimiter implements ratelimit.RateLimiter using GCRA in memory. Thread-safe for concurrent access. For development/testing only. Includes background cleanup to prevent unbounded memory growth.

func NewRateLimiter

func NewRateLimiter() *MemoryRateLimiter

NewRateLimiter creates a new in-memory rate limiter with default cleanup settings. Default cleanup interval: 5 minutes, default maxTTL: 1 hour.

func NewRateLimiterWithConfig

func NewRateLimiterWithConfig(cleanupInterval, maxTTL time.Duration) *MemoryRateLimiter

NewRateLimiterWithConfig creates a new in-memory rate limiter with custom cleanup settings. cleanupInterval: how often to run cleanup (e.g., 5 minutes) maxTTL: maximum age of a key before removal (e.g., 1 hour)

func (*MemoryRateLimiter) Allow

Allow checks if a request is allowed under the given rate limit config. Uses GCRA (Generic Cell Rate Algorithm) for smooth rate limiting.

func (*MemoryRateLimiter) Size

func (r *MemoryRateLimiter) Size() int

Size returns the current number of tracked keys. Useful for testing and monitoring memory usage.

func (*MemoryRateLimiter) StartCleanup

func (r *MemoryRateLimiter) StartCleanup(ctx context.Context)

StartCleanup starts the background cleanup goroutine. The goroutine periodically removes keys older than maxTTL. It stops when ctx is cancelled or Stop() is called.

func (*MemoryRateLimiter) Stop

func (r *MemoryRateLimiter) Stop()

Stop gracefully stops the cleanup goroutine and waits for it to exit. Safe to call multiple times.

type MemorySessionStore

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

MemorySessionStore implements session.SessionStore with in-memory map. Thread-safe for concurrent access. For development/testing only. Background cleanup goroutine removes expired sessions periodically.

func NewSessionStore

func NewSessionStore() *MemorySessionStore

NewSessionStore creates a new in-memory session store with default cleanup interval.

func NewSessionStoreWithConfig

func NewSessionStoreWithConfig(cleanupInterval time.Duration) *MemorySessionStore

NewSessionStoreWithConfig creates a new in-memory session store with custom cleanup interval.

func (*MemorySessionStore) Create

func (s *MemorySessionStore) Create(ctx context.Context, sess *session.Session) error

Create stores a new session.

func (*MemorySessionStore) Delete

func (s *MemorySessionStore) Delete(ctx context.Context, id string) error

Delete removes a session.

func (*MemorySessionStore) Get

Get retrieves a session by ID. Returns session.ErrSessionNotFound if session doesn't exist or is expired. Note: Expired sessions are NOT deleted here - background cleanup handles deletion.

func (*MemorySessionStore) Size

func (s *MemorySessionStore) Size() int

Size returns the number of sessions currently stored. Useful for testing cleanup behavior.

func (*MemorySessionStore) StartCleanup

func (s *MemorySessionStore) StartCleanup(ctx context.Context)

StartCleanup starts the background cleanup goroutine. The goroutine will periodically remove expired sessions. Call Stop() to stop the cleanup goroutine gracefully.

func (*MemorySessionStore) Stop

func (s *MemorySessionStore) Stop()

Stop stops the background cleanup goroutine and waits for it to exit. Safe to call multiple times.

func (*MemorySessionStore) Update

func (s *MemorySessionStore) Update(ctx context.Context, sess *session.Session) error

Update saves changes to an existing session.

type MemoryUpstreamStore

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

MemoryUpstreamStore implements upstream.UpstreamStore with an in-memory map. Thread-safe for concurrent access via sync.RWMutex. Returns deep copies to prevent external mutation of stored data.

func NewUpstreamStore

func NewUpstreamStore() *MemoryUpstreamStore

NewUpstreamStore creates a new in-memory upstream store.

func (*MemoryUpstreamStore) Add

Add stores a new upstream. Stores a deep copy to prevent external mutation.

func (*MemoryUpstreamStore) Delete

func (s *MemoryUpstreamStore) Delete(ctx context.Context, id string) error

Delete removes an upstream by ID. Returns ErrUpstreamNotFound if the upstream does not exist.

func (*MemoryUpstreamStore) Get

Get returns a single upstream by ID as a deep copy. Returns ErrUpstreamNotFound if the upstream does not exist.

func (*MemoryUpstreamStore) List

List returns all configured upstreams as deep copies.

func (*MemoryUpstreamStore) Update

Update replaces an existing upstream with a deep copy. Returns ErrUpstreamNotFound if the upstream does not exist.

Jump to

Keyboard shortcuts

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