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 ¶
- Variables
- func Merge(dst, src *Registry) error
- func MustAddFixed(v any)
- func MustAddReplaceable(v any)
- type Registry
- func (r *Registry) Add(v any) error
- func (r *Registry) AddWithCustomTag(v any, key string, val any) error
- func (r *Registry) GetByInterface(iface reflect.Type) []res.Entry
- func (r *Registry) GetByType(t reflect.Type) []res.Entry
- func (r *Registry) GetOneByInterface(iface reflect.Type) (any, error)
- func (r *Registry) GetOneByType(t reflect.Type) (any, error)
- func (r *Registry) MustAddFixed(v any)
- func (r *Registry) MustAddReplaceable(v any)
- func (r *Registry) Remove(v any) error
- func (r *Registry) Transform(fns ...res.TransformFunc) error
- func (r *Registry) WalkEntries(fn func(res.Entry) bool)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 (*Registry) Add ¶
Add registers v with res.TagRegular, replacing an existing res.TagReplaceable entry.
func (*Registry) AddWithCustomTag ¶ added in v0.22.0
AddWithCustomTag registers v with res.TagRegular and one custom tag key/value.
func (*Registry) GetOneByInterface ¶
func (*Registry) MustAddFixed ¶ added in v0.22.0
MustAddFixed registers v with res.TagFixed; panics on error.
func (*Registry) MustAddReplaceable ¶ added in v0.22.0
MustAddReplaceable registers v with res.TagReplaceable; panics on error.