Documentation
¶
Overview ¶
Package memory implements the zero-dependency reference store for the open-source core: request logging, the budget ledger, settings, and caller resolution all live in process memory. It is the offline runtime behind `cmd/proxy` when no SQLite path is configured, and the reference implementation for tests. Nothing here imports anything beyond stdlib and the core pkg/proxy seams.
Index ¶
- Constants
- type KeyStore
- type Store
- func (s *Store) CallerByKeyHash(ctx context.Context, hash string) (proxy.Caller, error)
- func (s *Store) GetSettings(_ context.Context) (proxy.SettingsRow, error)
- func (s *Store) LogRequest(_ context.Context, r proxy.RequestRecord) error
- func (s *Store) Logs() []proxy.RequestRecord
- func (s *Store) Set(hash string, c proxy.Caller)
- func (s *Store) SetCaller(hash string, c proxy.Caller)
- func (s *Store) SumActualCostForKeySince(_ context.Context, keyID string, since int64) (int64, error)
- func (s *Store) SumActualCostSince(_ context.Context, since int64) (int64, error)
- func (s *Store) UpdateSettings(_ context.Context, row proxy.SettingsRow) error
Constants ¶
const DefaultLoopThreshold = 2
DefaultLoopThreshold mirrors the detector's repeat-threshold default (first sighting passes, the second repeat blocks). It seeds SettingsRow until an UpdateSettings call.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyStore ¶
type KeyStore struct {
// contains filtered or unexported fields
}
KeyStore is an in-memory proxy.CallerStore: a SHA-256 key-hash -> Caller map for offline per-key budgets, seeded from a keys file or by tests. It is safe for concurrent use.
func (*KeyStore) CallerByKeyHash ¶
CallerByKeyHash implements proxy.CallerStore. An unknown hash surfaces as proxy.ErrInvalidKey so the middleware answers 401 (fail-closed).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the in-memory proxy.Store. It is safe for concurrent use: a single mutex serializes every read and write.
func New ¶
func New() *Store
New returns an empty in-memory Store. It satisfies proxy.Store and, through its embedded caller map, proxy.CallerStore.
func (*Store) CallerByKeyHash ¶
CallerByKeyHash implements proxy.CallerStore via the embedded KeyStore.
func (*Store) GetSettings ¶
GetSettings implements proxy.SettingsStore, returning the current snapshot or the defaults before the first update.
func (*Store) LogRequest ¶
LogRequest implements proxy.RequestLogStore by appending one record.
func (*Store) Logs ¶
func (s *Store) Logs() []proxy.RequestRecord
Logs returns a copy of every recorded request, oldest first. It is a test and diagnostics helper, not part of any seam.
func (*Store) Set ¶
Set binds (or replaces) the caller for a key hash. It matches KeyStore.Set, so cmd/proxy's loadKeys can seed the in-memory store (the -keys flag) through the same seam as KeyStore. hash is the lowercase hex SHA-256 of the raw key.
func (*Store) SetCaller ¶
SetCaller binds (or replaces) the caller for a key hash, for offline per-key budgets. It is an alias of Set kept for existing callers.
func (*Store) SumActualCostForKeySince ¶
func (s *Store) SumActualCostForKeySince(_ context.Context, keyID string, since int64) (int64, error)
SumActualCostForKeySince implements proxy.BudgetLedger: the sum of actual cost for one caller's requests at or after since. The empty keyID selects the anonymous/legacy bucket.
func (*Store) SumActualCostSince ¶
SumActualCostSince implements proxy.BudgetLedger: the sum of actual (non-loop-blocked) cost at or after since, across every caller.
func (*Store) UpdateSettings ¶
UpdateSettings implements proxy.SettingsStore by replacing the snapshot.