store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterSQLiteDriver added in v0.1.8

func RegisterSQLiteDriver() error

Types

type InMemoryStore

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

func NewInMemoryStore

func NewInMemoryStore(capacity int) *InMemoryStore

func (*InMemoryStore) Add

func (s *InMemoryStore) Add(log *model.RequestLog)

func (*InMemoryStore) Clear added in v0.1.8

func (s *InMemoryStore) Clear() error

Clear clears all stored request logs

func (*InMemoryStore) Close added in v0.1.4

func (s *InMemoryStore) Close() error

Close implements the Store interface but does nothing for in-memory store

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(id string) (*model.RequestLog, bool)

func (*InMemoryStore) GetAll

func (s *InMemoryStore) GetAll() []*model.RequestLog

func (*InMemoryStore) GetLatest

func (s *InMemoryStore) GetLatest(n int) []*model.RequestLog

type MongoDBStore added in v0.1.9

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

MongoDBStore implements the Store interface with MongoDB as backend

func NewMongoDBStore added in v0.1.9

func NewMongoDBStore(uri, databaseName, collectionName string, capacity int) (*MongoDBStore, error)

NewMongoDBStore creates a new MongoDB-backend store

func (*MongoDBStore) Add added in v0.1.9

func (m *MongoDBStore) Add(reqLog *model.RequestLog)

Add adds a new request log to the store

func (*MongoDBStore) Clear added in v0.1.9

func (m *MongoDBStore) Clear() error

Clear removes all logs from the store

func (*MongoDBStore) Close added in v0.1.9

func (m *MongoDBStore) Close() error

Close closes the database connection

func (*MongoDBStore) Get added in v0.1.9

func (m *MongoDBStore) Get(id string) (*model.RequestLog, bool)

Get retrieves a specific request log by its ID

func (*MongoDBStore) GetAll added in v0.1.9

func (m *MongoDBStore) GetAll() []*model.RequestLog

GetAll returns all stored request logs

func (*MongoDBStore) GetLatest added in v0.1.9

func (m *MongoDBStore) GetLatest(n int) []*model.RequestLog

GetLatest returns the n most recent request logs

type PostgresStore added in v0.1.4

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

PostgresStore implements the Store interface with PostgreSQL as backend

func NewPostgresStore added in v0.1.4

func NewPostgresStore(connStr, tableName string, capacity int) (*PostgresStore, error)

NewPostgresStore creates a new PostgreSQL-backed store

func (*PostgresStore) Add added in v0.1.4

func (s *PostgresStore) Add(reqLog *model.RequestLog)

Add adds a new request log to the store

func (*PostgresStore) Clear added in v0.1.8

func (s *PostgresStore) Clear() error

Clear clears all stored request logs

func (*PostgresStore) Close added in v0.1.4

func (s *PostgresStore) Close() error

Close closes the database connection

func (*PostgresStore) Get added in v0.1.4

func (s *PostgresStore) Get(id string) (*model.RequestLog, bool)

Get retrieves a specific request log by its ID

func (*PostgresStore) GetAll added in v0.1.4

func (s *PostgresStore) GetAll() []*model.RequestLog

GetAll returns all stored request logs

func (*PostgresStore) GetLatest added in v0.1.4

func (s *PostgresStore) GetLatest(n int) []*model.RequestLog

GetLatest returns the n most recent request logs

type RedisStore added in v0.1.4

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

RedisStore implements the Store interface with Redis as backend

func NewRedisStore added in v0.1.4

func NewRedisStore(connStr string, capacity int, ttlSeconds int) (*RedisStore, error)

NewRedisStore creates a new Redis-backed store

func (*RedisStore) Add added in v0.1.4

func (s *RedisStore) Add(reqLog *model.RequestLog)

Add adds a new request log to the store

func (*RedisStore) Clear added in v0.1.8

func (s *RedisStore) Clear() error

Clear removes all logs from the store

func (*RedisStore) Close added in v0.1.4

func (s *RedisStore) Close() error

Close closes the Redis client connection

func (*RedisStore) Get added in v0.1.4

func (s *RedisStore) Get(id string) (*model.RequestLog, bool)

Get retrieves a specific request log by its ID

func (*RedisStore) GetAll added in v0.1.4

func (s *RedisStore) GetAll() []*model.RequestLog

GetAll returns all stored request logs

func (*RedisStore) GetLatest added in v0.1.4

func (s *RedisStore) GetLatest(n int) []*model.RequestLog

GetLatest returns the n most recent request logs

type SQLiteStore added in v0.1.5

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

SQLiteStore implements the Store interface with SQLite as backend

func NewSQLiteStore added in v0.1.5

func NewSQLiteStore(dbPath, tableName string, capacity int) (*SQLiteStore, error)

NewSQLiteStore creates a new SQLite-backed store

func NewSQLiteStoreWithDB added in v0.1.8

func NewSQLiteStoreWithDB(db *sql.DB, tableName string, capacity int) (*SQLiteStore, error)

NewSQLiteStoreWithDB creates a new SQLite store with an existing database connection

func (*SQLiteStore) Add added in v0.1.5

func (s *SQLiteStore) Add(reqLog *model.RequestLog)

Add adds a new request log to the store

func (*SQLiteStore) Clear added in v0.1.8

func (s *SQLiteStore) Clear() error

Clear removes all logs from the store

func (*SQLiteStore) Close added in v0.1.5

func (s *SQLiteStore) Close() error

Close closes the database connection

func (*SQLiteStore) Get added in v0.1.5

func (s *SQLiteStore) Get(id string) (*model.RequestLog, bool)

Get retrieves a specific request log by its ID

func (*SQLiteStore) GetAll added in v0.1.5

func (s *SQLiteStore) GetAll() []*model.RequestLog

GetAll returns all stored request logs

func (*SQLiteStore) GetLatest added in v0.1.5

func (s *SQLiteStore) GetLatest(n int) []*model.RequestLog

GetLatest returns the n most recent request logs

type StorageConfig added in v0.1.4

type StorageConfig struct {
	// Type specifies which storage backend to use
	Type StorageType

	// Capacity is the maximum number of requests to store (applicable to memory store)
	Capacity int

	// ConnectionString is the database connection string (applicable to DB stores)
	ConnectionString string

	// TableName is the table name for SQL databases
	TableName string

	// TTL is the time-to-live for entries in Redis
	TTL int

	// ExistingDB is an existing database connection (applicable to StorageTypeSQLiteWithDB)
	ExistingDB *sql.DB
}

StorageConfig represents configuration options for storage backends

type StorageType added in v0.1.4

type StorageType string

StorageType represents the type of storage backend to use

const (
	// StorageTypeMemory represents in-memory storage
	StorageTypeMemory StorageType = "memory"

	// StorageTypePostgres represents PostgreSQL storage
	StorageTypePostgres StorageType = "postgres"

	// StorageTypeRedis represents Redis storage
	StorageTypeRedis StorageType = "redis"

	// StorageTypeSQLite represents SQLite storage
	StorageTypeSQLite StorageType = "sqlite"

	// StorageTypeSQLiteWithDB represents SQLite storage with existing connection
	StorageTypeSQLiteWithDB StorageType = "sqlite_with_db"

	// StorageTypeMongoDB represents MongoDB storage
	StorageTypeMongoDB StorageType = "mongodb"
)

type Store

type Store interface {
	// Add adds a new request log to the store
	Add(log *model.RequestLog)

	// Get retrieves a specific request log by its ID
	Get(id string) (*model.RequestLog, bool)

	// GetAll returns all stored request logs
	GetAll() []*model.RequestLog

	// Clear clears all stored request logs
	Clear() error

	// GetLatest returns the n most recent request logs
	GetLatest(n int) []*model.RequestLog

	// Close closes any open connections
	Close() error
}

Store defines the interface for all storage backends

func NewStore added in v0.1.4

func NewStore(config *StorageConfig) (Store, error)

NewStore creates a new storage backend based on configuration

Jump to

Keyboard shortcuts

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