factory

package
v0.0.0-...-2ff081f Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package factory provides configuration-based creation of distributed locks. It integrates with the config.DistributionLock configuration to create DLock instances with their respective providers.

Example:

f := factory.New(factory.WithNatsConn(conn), factory.WithLogger(logger))
dl, err := f.CreateDLockFromConfig(ctx, cfg)
if err != nil {
    log.Fatal(err)
}
defer dl.Close(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory struct {
	corefactory.Base
	// contains filtered or unexported fields
}

Factory creates distributed locks from configuration.

func New

func New(opts ...Option) *Factory

New creates a new Factory with the given options.

func (*Factory) CreateDLockFromConfig

func (f *Factory) CreateDLockFromConfig(ctx context.Context, cfg *config.DistributionLock) (*dlock.DLock, error)

CreateDLockFromConfig creates a DLock from configuration.

func (*Factory) CreateNatsDLockFromConfig

func (f *Factory) CreateNatsDLockFromConfig(ctx context.Context, cfg *config.DistributionLockNats) (*dlock.DLock, error)

CreateNatsDLockFromConfig creates a DLock with NATS provider.

func (*Factory) CreateNoopDLock

func (f *Factory) CreateNoopDLock() *dlock.DLock

CreateNoopDLock creates a DLock with no-op provider for testing.

type Option

type Option func(o *options)

Option is a functional option for configuring options.

func WithLogger

func WithLogger(v *slog.Logger) Option

WithLogger sets the logger option.

func WithNatsConn

func WithNatsConn(v *nats.Conn) Option

WithNatsConn sets the natsConn option.

Jump to

Keyboard shortcuts

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