Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataLoader ¶
type DataLoader[T any] interface { // FromFile loads data from a local file FromFile(ctx context.Context, path string) ([]T, error) // FromRemote loads data from a remote URL FromRemote(ctx context.Context, url, auth string) ([]T, error) // FromRedis loads data from Redis FromRedis(ctx context.Context, client interface{}, key string) ([]T, error) // Load loads data from multiple sources // Sources are processed in priority order (lower number = higher priority) // Behavior depends on LoadStrategy: // - LoadStrategyFallback: returns data from the first successful source // - LoadStrategyMerge: merges data from all successful sources with deduplication Load(ctx context.Context, sources ...Source) ([]T, error) }
DataLoader is a generic interface for loading data from various sources
func NewLoader ¶
func NewLoader[T any](opts *LoadOptions) (DataLoader[T], error)
NewLoader creates a new generic data loader
func NewLoaderWithNormalize ¶
func NewLoaderWithNormalize[T any](opts *LoadOptions, normalizeFunc NormalizeFunc[T]) (DataLoader[T], error)
NewLoaderWithNormalize creates a new generic data loader with normalization function
type KeyFunc ¶
KeyFunc extracts a unique key from an item for deduplication Returns the key and true if the item should be included, false otherwise
type LoadOptions ¶
type LoadOptions struct {
// MaxFileSize limits the maximum file size to read (default: 10MB)
MaxFileSize int64
// MaxRetries for remote requests (default: 3)
MaxRetries int
// RetryDelay for remote requests (default: 1s)
RetryDelay time.Duration
// HTTPTimeout for remote requests (default: 5s)
HTTPTimeout time.Duration
// InsecureSkipVerify allows skipping TLS certificate verification (default: false)
// Only use in development environments
InsecureSkipVerify bool
// AllowEmptyFile if true, returns empty slice instead of error when file not found (default: false)
AllowEmptyFile bool
// AllowEmptyData if true, continues to next source even if current source returns empty data (default: false)
AllowEmptyData bool
// LoadStrategy determines how to combine data from multiple sources (default: LoadStrategyFallback)
// - LoadStrategyFallback: return data from first successful source
// - LoadStrategyMerge: merge data from all successful sources with deduplication
LoadStrategy LoadStrategy
// KeyFunc is required when LoadStrategy is LoadStrategyMerge
// It extracts a unique key from each item for deduplication
// Note: This is stored as interface{} and will be type-asserted in the loader
KeyFunc interface{} // Should be KeyFunc[T] but we can't use generics in struct fields
}
LoadOptions configures the behavior of Load operations
func DefaultLoadOptions ¶
func DefaultLoadOptions() *LoadOptions
DefaultLoadOptions returns default load options
type LoadStrategy ¶
type LoadStrategy string
LoadStrategy determines how data from multiple sources should be combined
const ( // LoadStrategyFallback returns data from the first successful source (default) LoadStrategyFallback LoadStrategy = "fallback" // LoadStrategyMerge merges data from all successful sources with deduplication LoadStrategyMerge LoadStrategy = "merge" )
type NormalizeFunc ¶
type NormalizeFunc[T any] func([]T) []T
NormalizeFunc is a function type for normalizing data after parsing It accepts a slice of any type and returns a normalized slice
type Source ¶
type Source struct {
Type SourceType
Priority int // Lower number = higher priority (0 is highest)
Config SourceConfig
}
Source represents a data source with priority
type SourceConfig ¶
type SourceConfig struct {
// For file source
FilePath string
// For Redis source
RedisKey string
RedisClient interface{} // *redis.Client from redis-kit
// For remote source
RemoteURL string
AuthorizationHeader string
Timeout time.Duration
InsecureSkipVerify bool
}
SourceConfig holds configuration for a data source
type SourceType ¶
type SourceType string
SourceType represents the type of data source
const ( // SourceTypeFile represents a local file source SourceTypeFile SourceType = "file" // SourceTypeRedis represents a Redis source SourceTypeRedis SourceType = "redis" // SourceTypeRemote represents a remote HTTP/HTTPS source SourceTypeRemote SourceType = "remote" )