factory

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory[T any] struct {
	// contains filtered or unexported fields
}

func NewFactory

func NewFactory[T any]() *Factory[T]

func (*Factory[T]) Get

func (f *Factory[T]) Get(name string) (func() T, error)

func (*Factory[T]) Register

func (f *Factory[T]) Register(name string, fn func() T) error

Register registers a new build functionx. The name is the key used to retrieve the build functionx. If the name is already registered, returns an error. The name is not case sensitive.

func (*Factory[T]) Unregister

func (f *Factory[T]) Unregister(name string) error

type SafeFactory

type SafeFactory[T any] struct {
	// contains filtered or unexported fields
}

SafeFactory is a factory that can create objects of type T. It is safe for concurrent use.

func NewSafeFactory

func NewSafeFactory[T any]() *SafeFactory[T]

func (*SafeFactory[T]) Get

func (f *SafeFactory[T]) Get(name string) (func() (T, error), error)

func (*SafeFactory[T]) Register

func (f *SafeFactory[T]) Register(name string, fn func() (T, error)) error

Register registers a new factory functionx for the given type. The name is used to identify the type in the factory. If the name is already registered, returns an error. it is not case sensitive.

func (*SafeFactory[T]) Unregister

func (f *SafeFactory[T]) Unregister(name string) error

Jump to

Keyboard shortcuts

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