Documentation
¶
Overview ¶
Package factory provides a fluent builder for creating cursor storages from configuration.
CursorStorageBuilder uses a fluent API with deferred error accumulation: errors from any step are collected and returned at CursorStorageBuilder.Build time.
storage, err := factory.New(cfg.Storage).
UseLogger(logger).
UseRedisClient(redisClient).
WithTTL(time.Hour).
Build(ctx)
Index ¶
- Constants
- type CursorStorageBuilder
- func (b *CursorStorageBuilder) Build(ctx context.Context) (mongo.CursorStorage, error)
- func (b *CursorStorageBuilder) UseDefaultLogger() *CursorStorageBuilder
- func (b *CursorStorageBuilder) UseJetstream(v jetstream.JetStream) *CursorStorageBuilder
- func (b *CursorStorageBuilder) UseLogger(v *slog.Logger) *CursorStorageBuilder
- func (b *CursorStorageBuilder) UseRedisClient(v redis.UniversalClient) *CursorStorageBuilder
- func (b *CursorStorageBuilder) UseScheduler(v corescheduler.TaskRegistrar) *CursorStorageBuilder
- func (b *CursorStorageBuilder) WithTTL(ttl time.Duration) *CursorStorageBuilder
Constants ¶
const (
// DefaultBucket is the default NATS KeyValue bucket name for cursor storage.
DefaultBucket = "cursor"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CursorStorageBuilder ¶
type CursorStorageBuilder struct {
corefactory.Base
// contains filtered or unexported fields
}
CursorStorageBuilder assembles a mongo.CursorStorage step by step using a fluent API. Create instances with New. Errors are accumulated and reported at CursorStorageBuilder.Build time. The builder is not safe for concurrent use.
func New ¶
func New(cfg *config.CacheStorageConfig) *CursorStorageBuilder
New creates a CursorStorageBuilder for the given cache storage config. Config can be nil — the error surfaces at CursorStorageBuilder.Build time.
func (*CursorStorageBuilder) Build ¶
func (b *CursorStorageBuilder) Build(ctx context.Context) (mongo.CursorStorage, error)
Build assembles the cursor storage. Errors from fluent methods are accumulated and reported here via errors.Join.
func (*CursorStorageBuilder) UseDefaultLogger ¶
func (b *CursorStorageBuilder) UseDefaultLogger() *CursorStorageBuilder
UseDefaultLogger sets the logger to slog.Default.
func (*CursorStorageBuilder) UseJetstream ¶
func (b *CursorStorageBuilder) UseJetstream(v jetstream.JetStream) *CursorStorageBuilder
UseJetstream sets the NATS JetStream context for NATS storage backends.
func (*CursorStorageBuilder) UseLogger ¶
func (b *CursorStorageBuilder) UseLogger(v *slog.Logger) *CursorStorageBuilder
UseLogger sets the logger for the builder and all created components.
func (*CursorStorageBuilder) UseRedisClient ¶
func (b *CursorStorageBuilder) UseRedisClient(v redis.UniversalClient) *CursorStorageBuilder
UseRedisClient sets the Redis client for Redis storage backends.
func (*CursorStorageBuilder) UseScheduler ¶
func (b *CursorStorageBuilder) UseScheduler(v corescheduler.TaskRegistrar) *CursorStorageBuilder
UseScheduler sets the scheduler for background task registration.
func (*CursorStorageBuilder) WithTTL ¶
func (b *CursorStorageBuilder) WithTTL(ttl time.Duration) *CursorStorageBuilder
WithTTL sets the TTL for cursor storage entries.