inheritance

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package inheritance is a hierarchical config resolver: combine multiple partial-config layers (defaults → env → scope → instance) into a fully-realised config by taking the highest-priority definition per field.

Each field is wrapped in Optional[T] to distinguish "set" from "unset". Append-merge for slices and union-merge for maps are available via the `cfg:"...,merge=…"` tag; the default is override.

Complements kit/sops + envconfig (boot-time parsing) by handling runtime layered lookup with merging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Layer

type Layer[T any] struct {
	Name string
	Data T
}

Layer is one priority level in a hierarchical config. Higher-index layers (added later via AddLayer) override lower ones.

type Optional

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

Optional is a "set or unset" wrapper used in Layer structs.

func Set

func Set[T any](v T) Optional[T]

Set wraps a value as "explicitly set".

func Unset

func Unset[T any]() Optional[T]

Unset returns the zero Optional[T] representing "no value provided".

func (Optional[T]) Get

func (o Optional[T]) Get() (T, bool)

Get returns the value and whether it was set.

func (Optional[T]) IsSet

func (o Optional[T]) IsSet() bool

IsSet reports whether the value was provided.

func (Optional[T]) MarshalJSON

func (o Optional[T]) MarshalJSON() ([]byte, error)

MarshalJSON emits the underlying value when set, JSON null when unset, so round-trips don't accidentally promote unset → zero.

func (Optional[T]) OrDefault

func (o Optional[T]) OrDefault(d T) T

OrDefault returns the value if set, otherwise d.

func (*Optional[T]) UnmarshalJSON

func (o *Optional[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON treats JSON null as Unset; any other value as Set.

type ResolutionError

type ResolutionError struct {
	Field  string
	Reason string
}

ResolutionError is one structured per-field problem from Resolve.

func (ResolutionError) Error

func (e ResolutionError) Error() string

Error implements the error interface.

type Resolver

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

Resolver merges layers of T into a final T.

func NewResolver

func NewResolver[T any]() *Resolver[T]

NewResolver constructs an empty Resolver.

func (*Resolver[T]) AddLayer

func (r *Resolver[T]) AddLayer(l Layer[T])

AddLayer appends a layer. Later AddLayer calls have higher priority.

func (*Resolver[T]) Resolve

func (r *Resolver[T]) Resolve() (T, []ResolutionError)

Resolve produces a fully-realised T plus any per-field errors (required fields unset, type mismatches).

Jump to

Keyboard shortcuts

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