Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Fields
- type FileConfig
- type Logger
- type MemoryConfig
- type MemoryStorage
- func (ms *MemoryStorage) Clear() error
- func (ms *MemoryStorage) Close() error
- func (ms *MemoryStorage) Delete(ctx context.Context, key string) error
- func (ms *MemoryStorage) Get(ctx context.Context, key string) ([]byte, error)
- func (ms *MemoryStorage) GetAll(ctx context.Context) (map[string][]byte, error)
- func (ms *MemoryStorage) GetMultiple(ctx context.Context, keys []string) (map[string][]byte, error)
- func (ms *MemoryStorage) GetStats() Stats
- func (ms *MemoryStorage) Increment(ctx context.Context, key string, ttl time.Duration) (int64, error)
- func (ms *MemoryStorage) ListKeysWithPrefix(ctx context.Context, prefix string) ([]string, error)
- func (ms *MemoryStorage) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (ms *MemoryStorage) SetMultiple(ctx context.Context, items map[string][]byte, ttl time.Duration) error
- type Stats
Constants ¶
const ( // Log levels LogLevelDebug = "debug" LogLevelInfo = "info" LogLevelWarn = "warn" LogLevelError = "error" LogLevelFatal = "fatal" // Log formats LogFormatJSON = "json" LogFormatText = "text" // Log outputs LogOutputStdout = "stdout" LogOutputStderr = "stderr" LogOutputFile = "file" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Level is the minimum log level (debug, info, warn, error, fatal)
Level string `json:"level" yaml:"level"`
// Format is the output format (json, console)
Format string `json:"format" yaml:"format"`
// Output destinations (stdout, file, etc.)
Outputs []string `yaml:"outputs,omitempty" json:"outputs,omitempty"`
// File output settings
File FileConfig `json:"file" yaml:"file"`
}
Config holds logger configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default logger configuration
type FileConfig ¶
type FileConfig struct {
// Path to log file
Path string `json:"path" yaml:"path"`
// MaxSize in megabytes
MaxSize int `json:"max_size" yaml:"max_size"`
// MaxAge in days
MaxAge int `json:"max_age" yaml:"max_age"`
// MaxBackups to keep
MaxBackups int `json:"max_backups" yaml:"max_backups"`
// Compress rotated files
Compress bool `json:"compress" yaml:"compress"`
}
FileConfig for file output
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger wraps zerolog with additional functionality
type MemoryConfig ¶
type MemoryConfig struct {
// CleanupInterval determines how often expired entries are removed.
// Default is 1 minute if not specified.
CleanupInterval time.Duration
}
MemoryConfig holds configuration for in-memory storage.
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage implements the Storage interface using an in-memory map. It provides thread-safe operations with automatic cleanup of expired entries.
func NewMemoryStorage ¶
func NewMemoryStorage(config *MemoryConfig) *MemoryStorage
NewMemoryStorage creates a new in-memory storage instance. If config is nil, default values are used.
func (*MemoryStorage) Clear ¶
func (ms *MemoryStorage) Clear() error
Clear removes all entries from storage but keeps it operational.
func (*MemoryStorage) Close ¶
func (ms *MemoryStorage) Close() error
Close gracefully shuts down the storage and releases resources.
func (*MemoryStorage) Delete ¶
func (ms *MemoryStorage) Delete(ctx context.Context, key string) error
Delete removes the key and its associated value from storage. No error is returned if the key doesn't exist.
func (*MemoryStorage) Get ¶
Get retrieves the value associated with the given key. Returns ErrKeyNotFound if the key doesn't exist or has expired.
func (*MemoryStorage) GetAll ¶
GetAll returns all key-value pairs in storage (excluding expired entries).
func (*MemoryStorage) GetMultiple ¶
GetMultiple retrieves multiple values in a single operation. Returns a map of key-value pairs for existing keys.
func (*MemoryStorage) GetStats ¶
func (ms *MemoryStorage) GetStats() Stats
GetStats returns current storage statistics.
func (*MemoryStorage) Increment ¶
func (ms *MemoryStorage) Increment(ctx context.Context, key string, ttl time.Duration) (int64, error)
Increment atomically increments a counter for the given key. If the key doesn't exist, it is created with value 1. The TTL is set for new keys or updated for existing keys.
func (*MemoryStorage) ListKeysWithPrefix ¶
ListKeysWithPrefix returns all keys that start with the given prefix. This is useful for finding all replica keys or other categorized keys.
func (*MemoryStorage) Set ¶
func (ms *MemoryStorage) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
Set stores a value with the given key and TTL. If TTL is 0, the value will not expire.
func (*MemoryStorage) SetMultiple ¶
func (ms *MemoryStorage) SetMultiple(ctx context.Context, items map[string][]byte, ttl time.Duration) error
SetMultiple stores multiple key-value pairs in a single operation.