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
- Variables
- type AuthStore
- func (s *AuthStore) AddIdentity(identity *auth.Identity)
- func (s *AuthStore) AddKey(key *auth.APIKey)
- func (s *AuthStore) GetAPIKey(ctx context.Context, keyHash string) (*auth.APIKey, error)
- func (s *AuthStore) GetIdentity(ctx context.Context, id string) (*auth.Identity, error)
- func (s *AuthStore) ListAPIKeys(ctx context.Context) ([]*auth.APIKey, error)
- func (s *AuthStore) RemoveKey(keyField string)
- type MemoryAuditStore
- func (s *MemoryAuditStore) Append(ctx context.Context, records ...audit.AuditRecord) error
- func (s *MemoryAuditStore) Close() error
- func (s *MemoryAuditStore) Flush(ctx context.Context) error
- func (s *MemoryAuditStore) GetRecent(n int) []audit.AuditRecord
- func (s *MemoryAuditStore) Query(filter audit.AuditFilter) ([]audit.AuditRecord, string, error)
- type MemoryPolicyStore
- func (s *MemoryPolicyStore) AddPolicy(p *policy.Policy)
- func (s *MemoryPolicyStore) DeletePolicy(ctx context.Context, id string) error
- func (s *MemoryPolicyStore) DeleteRule(ctx context.Context, policyID, ruleID string) error
- func (s *MemoryPolicyStore) GetAllPolicies(ctx context.Context) ([]policy.Policy, error)
- func (s *MemoryPolicyStore) GetPolicy(ctx context.Context, id string) (*policy.Policy, error)
- func (s *MemoryPolicyStore) GetPolicyWithRules(ctx context.Context, id string) (*policy.Policy, error)
- func (s *MemoryPolicyStore) SavePolicy(ctx context.Context, p *policy.Policy) error
- func (s *MemoryPolicyStore) SaveRule(ctx context.Context, policyID string, r *policy.Rule) error
- type MemoryRateLimiter
- type MemorySessionStore
- func (s *MemorySessionStore) Create(ctx context.Context, sess *session.Session) error
- func (s *MemorySessionStore) Delete(ctx context.Context, id string) error
- func (s *MemorySessionStore) Get(ctx context.Context, id string) (*session.Session, error)
- func (s *MemorySessionStore) Size() int
- func (s *MemorySessionStore) StartCleanup(ctx context.Context)
- func (s *MemorySessionStore) Stop()
- func (s *MemorySessionStore) Update(ctx context.Context, sess *session.Session) error
- type MemoryUpstreamStore
- func (s *MemoryUpstreamStore) Add(ctx context.Context, u *upstream.Upstream) error
- func (s *MemoryUpstreamStore) Delete(ctx context.Context, id string) error
- func (s *MemoryUpstreamStore) Get(ctx context.Context, id string) (*upstream.Upstream, error)
- func (s *MemoryUpstreamStore) List(ctx context.Context) ([]upstream.Upstream, error)
- func (s *MemoryUpstreamStore) Update(ctx context.Context, u *upstream.Upstream) error
Constants ¶
const DefaultCleanupInterval = 1 * time.Minute
Default cleanup interval for session expiration.
Variables ¶
var ( ErrKeyNotFound = errors.New("api key not found") ErrIdentityNotFound = errors.New("identity not found") )
Error types for auth store operations.
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 (*AuthStore) AddIdentity ¶
AddIdentity adds an identity (for testing/seeding).
func (*AuthStore) GetAPIKey ¶
GetAPIKey retrieves an API key by its hash. Returns ErrKeyNotFound if key doesn't exist.
func (*AuthStore) GetIdentity ¶
GetIdentity retrieves user identity by ID. Returns ErrIdentityNotFound if identity doesn't exist.
func (*AuthStore) ListAPIKeys ¶
ListAPIKeys returns all stored API keys for iteration-based verification.
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) 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 ¶
func (s *MemoryAuditStore) Query(filter audit.AuditFilter) ([]audit.AuditRecord, string, error)
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 ¶
GetAllPolicies returns all enabled policies.
func (*MemoryPolicyStore) GetPolicy ¶
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 ¶
SavePolicy creates or updates 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 ¶
func (r *MemoryRateLimiter) Allow(ctx context.Context, key string, config ratelimit.RateLimitConfig) (ratelimit.RateLimitResult, error)
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) 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.
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.