inventory

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: GPL-3.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package inventory computes the static list of configuration keys a dsco-managed struct expects, given a set of layers, without performing any I/O.

See https://github.com/byte4ever/dsco for the parent project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Satisfied *Satisfaction `json:"satisfied,omitempty" yaml:"satisfied,omitempty"`
	Key       *KeySpec      `json:"key,omitempty"       yaml:"key,omitempty"`
	Path      string        `json:"path"                yaml:"path"`
	GoType    string        `json:"go_type"             yaml:"go_type"`
}

Field describes the canonical key (and any baked-in default) for one leaf field of the config struct.

func (Field) MarshalJSON

func (f Field) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler so Field keys are emitted in human-readable order: path, go_type, satisfied, key.

func (Field) MarshalYAML

func (f Field) MarshalYAML() (any, error)

MarshalYAML implements yaml.InterfaceMarshaler so Field keys are emitted in human-readable order: path, go_type, satisfied, key.

type KeySpec

type KeySpec struct {
	Layer string `json:"layer" yaml:"layer"`
	Key   string `json:"key"   yaml:"key"`
}

KeySpec is the canonical key form the first string-based layer (in declaration order) that can supply this field would accept.

type Report

type Report struct {
	Type   string  `json:"type"   yaml:"type"`
	Fields []Field `json:"fields" yaml:"fields"`
}

Report is the static inventory of a config struct against a layer set.

func Compute

func Compute(cfg any, layers ...dsco.Layer) (*Report, error)

Compute walks the model and layer builders exactly like dsco.Fill, but instead of loading values it returns the canonical key each string-based layer would accept for every required leaf field of cfg. No environment variables, command-line arguments, or files are read.

cfg must be **T (pointer to a pointer to a struct), mirroring the Fill calling convention: var c *MyConfig; Compute(&c, layers...).

Pattern: Factory — assembles a Report from model + layers without I/O.

func (*Report) WriteJSON

func (r *Report) WriteJSON(writer io.Writer) error

WriteJSON writes the inventory as JSON via github.com/goccy/go-json. Indentation is two spaces; output ends with a trailing newline.

func (*Report) WriteText

func (r *Report) WriteText(writer io.Writer) error

WriteText writes a human-readable, fixed-width-column inventory to writer. Columns: PATH | TYPE | KEY | DEFAULT. Empty cells render as "—". Long default values are truncated with ellipsis. Output ends with a trailing newline.

func (*Report) WriteYAML

func (r *Report) WriteYAML(writer io.Writer) error

WriteYAML writes the inventory as YAML via github.com/goccy/go-yaml. Output ends with a trailing newline.

type Satisfaction

type Satisfaction struct {
	Value   any    `json:"value"    yaml:"value"`
	LayerID string `json:"layer_id" yaml:"layer_id"`
}

Satisfaction records that a struct layer already provides a value for this field.

func (Satisfaction) MarshalJSON

func (s Satisfaction) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler so Satisfaction.Value is normalized before serialization.

func (Satisfaction) MarshalYAML

func (s Satisfaction) MarshalYAML() (any, error)

MarshalYAML implements yaml.InterfaceMarshaler so Satisfaction.Value is normalized before serialization.

Jump to

Keyboard shortcuts

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