pkg

package
v0.0.0-...-ee0cddb Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var (
	// ErrKeyNotFound is returned when a key doesn't exist
	ErrKeyNotFound = errors.New("key not found")

	// ErrContextCanceled is returned when the context is canceled
	ErrContextCanceled = errors.New("context canceled")

	// ErrStorageUnavailable is returned when storage is closed
	ErrStorageUnavailable = errors.New("storage unavailable")
)

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 Fields

type Fields map[string]any

Fields is a map of fields to add to log entries

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

func NewLogger

func NewLogger(cfg *Config) (*Logger, error)

NewLogger creates a new logger instance

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields Fields)

Debug logs a debug message with optional fields.

func (*Logger) Error

func (l *Logger) Error(msg string, fields Fields)

Error logs an error message with optional fields.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields Fields)

Fatal logs a fatal message with optional fields and exits the program.

func (*Logger) Info

func (l *Logger) Info(msg string, fields Fields)

Info logs an info message with optional fields.

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields Fields)

Warn logs a warning message with optional fields.

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

func (ms *MemoryStorage) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves the value associated with the given key. Returns ErrKeyNotFound if the key doesn't exist or has expired.

func (*MemoryStorage) GetAll

func (ms *MemoryStorage) GetAll(ctx context.Context) (map[string][]byte, error)

GetAll returns all key-value pairs in storage (excluding expired entries).

func (*MemoryStorage) GetMultiple

func (ms *MemoryStorage) GetMultiple(ctx context.Context, keys []string) (map[string][]byte, error)

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

func (ms *MemoryStorage) ListKeysWithPrefix(ctx context.Context, prefix string) ([]string, error)

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.

type Stats

type Stats struct {
	Entries   int
	Hits      int64
	Misses    int64
	Sets      int64
	Deletes   int64
	Evictions int64
}

Stats returns current storage statistics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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