unique

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package unique is a type-unique registry: at most one res.Entry per concrete type.

System tag policy (res.TagRegular, res.TagReplaceable, res.TagFixed) is enforced on Add. Library use init registers defaults via MustAddReplaceable or MustAddFixed on Global.

App bootstrap API:

unique.Add(v)                              — materialized resource
unique.AddWithCustomTag(v, key, val)       — spec + custom tag (e.g. ecfg segment)
entry.ChangeValue(built)                   — materialize spec in-place (via WalkEntries)
unique.Merge(main, side)                   — merge app catalog into main

MustAddReplaceable and MustAddFixed are the only public init entry points for Replaceable/Fixed.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFixed         = errors.New("unique: cannot override entry with TagFixed")
	ErrRegularExists = errors.New("unique: entry for type already has TagRegular")
	ErrTypeOccupied  = errors.New("unique: entry for type has incompatible tag")
	ErrDuplicateType = errors.New("unique: multiple entries for same concrete type")
)

Functions

func Merge

func Merge(dst, src *Registry) error

Merge copies resources from src into dst by calling Registry.Add or Registry.AddWithCustomTag.

func MustAddFixed added in v0.21.1

func MustAddFixed(v any)

MustAddFixed registers v on Global with res.TagFixed; panics on error.

func MustAddReplaceable added in v0.21.1

func MustAddReplaceable(v any)

MustAddReplaceable registers v on Global with res.TagReplaceable; panics on error.

Types

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func Global

func Global() *Registry

Global returns the shared type-unique composition-root registry.

func New

func New() *Registry

New returns an empty type-unique registry backed by res.New.

func (*Registry) Add

func (r *Registry) Add(v any) error

Add registers v with res.TagRegular, replacing an existing res.TagReplaceable entry.

func (*Registry) AddWithCustomTag added in v0.22.0

func (r *Registry) AddWithCustomTag(v any, key string, val any) error

AddWithCustomTag registers v with res.TagRegular and one custom tag key/value.

func (*Registry) GetByInterface

func (r *Registry) GetByInterface(iface reflect.Type) []res.Entry

func (*Registry) GetByType

func (r *Registry) GetByType(t reflect.Type) []res.Entry

func (*Registry) GetOneByInterface

func (r *Registry) GetOneByInterface(iface reflect.Type) (any, error)

func (*Registry) GetOneByType

func (r *Registry) GetOneByType(t reflect.Type) (any, error)

func (*Registry) MustAddFixed added in v0.22.0

func (r *Registry) MustAddFixed(v any)

MustAddFixed registers v with res.TagFixed; panics on error.

func (*Registry) MustAddReplaceable added in v0.22.0

func (r *Registry) MustAddReplaceable(v any)

MustAddReplaceable registers v with res.TagReplaceable; panics on error.

func (*Registry) Remove

func (r *Registry) Remove(v any) error

func (*Registry) Transform

func (r *Registry) Transform(fns ...res.TransformFunc) error

func (*Registry) WalkEntries

func (r *Registry) WalkEntries(fn func(res.Entry) bool)

Jump to

Keyboard shortcuts

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