Help us shape the future of Go! Take the 2026 Go Developer Survey

cyfct

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get added in v0.2.4

func Get[T any]() (T, error)

Get retrieves a singleton instance of type T. Returns an error if the instance is not found or type mismatch occurs.

func GetByGroup added in v0.2.4

func GetByGroup[T any](group string) ([]T, error)

GetByGroup is deprecated, use GetGroup instead. Kept for backward compatibility.

func GetGroup added in v0.2.4

func GetGroup[T any](group string) ([]T, error)

GetGroup retrieves all singleton instances of type T associated with a group.

func GetGroupWithCtx added in v0.2.4

func GetGroupWithCtx[T any](ctx context.Context, group string) ([]T, error)

GetGroupWithCtx retrieves all singleton instances of type T associated with a group with context. The context is passed to creator functions if they accept a context parameter.

func GetInstance

func GetInstance[T any]() (T, error)

GetInstance is deprecated, use Get instead. Kept for backward compatibility.

func GetWithCtx added in v0.2.4

func GetWithCtx[T any](ctx context.Context) (T, error)

GetWithCtx retrieves a singleton instance of type T with context. The context is passed to the creator function if it accepts a context parameter. Returns an error if the instance is not found or type mismatch occurs.

func MustGet added in v0.2.4

func MustGet[T any]() T

MustGet retrieves a singleton instance of type T, panics on failure. This is useful in init() functions where error handling is not possible.

func MustGetInstance added in v0.2.4

func MustGetInstance[T any]() T

MustGetInstance is an alias for MustGet, retrieves a singleton instance and panics on failure.

func Register added in v0.2.4

func Register[T any](creator func() (T, error))

Register registers a factory function for creating singleton instances of type T. The creator function does not receive a context.

func RegisterFactory

func RegisterFactory[T any](creator func() (T, error))

RegisterFactory is deprecated, use Register instead. Kept for backward compatibility.

func RegisterGroup added in v0.2.4

func RegisterGroup[T any](group string, creator func() (T, error))

RegisterGroup registers a factory function and associates it with a group. The creator function does not receive a context.

func RegisterGroupWithCtx added in v0.2.4

func RegisterGroupWithCtx[T any](group string, creator func(context.Context) (T, error))

RegisterGroupWithCtx registers a factory function that accepts a context and associates it with a group. The context will be passed when the instance is created.

func RegisterWithCtx added in v0.2.4

func RegisterWithCtx[T any](creator func(context.Context) (T, error))

RegisterWithCtx registers a factory function that accepts a context parameter. The context will be passed when the instance is created.

Types

This section is empty.

Jump to

Keyboard shortcuts

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