factory

package
v0.0.0-...-c7901e9 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 14 Imported by: 0

README

factory

import "github.com/altessa-s/go-atlas/data/mongo/factory"

Package factory provides a fluent builder for creating a MongoDB cursor storage from configuration. CursorStorageBuilder uses deferred error accumulation — errors from any step are collected and returned at Build() time.

Quick Start

storage, err := factory.New(cfg.CursorStorage).
    UseLogger(logger).
    UseRedisClient(redisClient).
    WithTTL(24 * time.Hour).
    Build(ctx)

Supported Storage Types

Type Backend Requires
memory In-process map UseScheduler (optional)
redis Redis UseRedisClient
nats NATS JetStream KV UseJetstream

Methods

Constructor
Method Description
New(cfg) Creates a CursorStorageBuilder for the given cache storage config
Dependencies
Method Description
UseLogger Sets the logger for the builder and all created components
UseRedisClient Sets the Redis client for Redis storage backends
UseJetstream Sets the NATS JetStream context for NATS storage backends
UseScheduler Sets the scheduler for background cleanup task registration
Configuration
Method Description
WithTTL(ttl) Sets the TTL applied to all cursor storage entries
Terminal
Method Description
Build(ctx) Assembles and returns the cursor storage

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

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

New creates a CursorStorageBuilder for the given cache storage config. Config can be nil — the error surfaces at CursorStorageBuilder.Build time.

func (*CursorStorageBuilder) Build

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

UseJetstream sets the NATS JetStream context for NATS storage backends.

func (*CursorStorageBuilder) UseLogger

UseLogger sets the logger for the builder and all created components.

func (*CursorStorageBuilder) UseRedisClient

UseRedisClient sets the Redis client for Redis storage backends.

func (*CursorStorageBuilder) UseScheduler

UseScheduler sets the scheduler for background task registration.

func (*CursorStorageBuilder) WithTTL

WithTTL sets the TTL for cursor storage entries.

Jump to

Keyboard shortcuts

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