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

config

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config composes a project's configuration from its layers and remembers where each value came from. The order, lowest first: plugin and pack defaults, imports, includes, rig.yaml, then .rig/local.yaml; afterwards `defaults:` and `templates:`/`extends` fill each entry. A layer above wins key by key, and `key: null` drops what the layers below say.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(importer, version string, watch ...string) (string, error)

Key is the sha256 of the importer, its version and the files it watches (directories walked).

func Value

func Value(n *yaml.Node, key string) *yaml.Node

Value is the value of key in mapping n, or nil.

Types

type Cache

type Cache struct{ Dir string }

Cache keeps importers' fragments in dir, keyed by what they read, so a warm load parses no foreign files.

func (Cache) Get

func (c Cache) Get(key string) (*yaml.Node, bool)

func (Cache) Put

func (c Cache) Put(key string, n *yaml.Node) error

type Doc

type Doc struct {
	Root *yaml.Node
	// contains filtered or unexported fields
}

Doc is a configuration as a YAML tree, with each node's origin and, per path, every layer that set it.

func Compose

func Compose(raw []byte, file string, o Options) (*Doc, error)

Compose builds a project's configuration from rig.yaml (raw, at file) and every layer around it.

func FromNode

func FromNode(n *yaml.Node, file, layer string) *Doc

FromNode makes a layer from a tree built in memory, such as an importer's fragment.

func Parse

func Parse(raw []byte, file, layer string) (*Doc, error)

Parse reads one layer; an empty file is an empty mapping.

func (*Doc) ApplyTemplates added in v0.35.1

func (d *Doc) ApplyTemplates(file string) error

ApplyTemplates is what Compose does last unless NoTemplates.

func (*Doc) Bytes

func (d *Doc) Bytes() ([]byte, error)

Bytes is the composed document as YAML.

func (*Doc) Explain

func (d *Doc) Explain(path string) []Origin

Explain is every layer that set path, lowest first; the last one won.

func (*Doc) Finish

func (d *Doc) Finish()

Finish drops the tombstones: every key whose null overrode a lower layer.

func (*Doc) Get

func (d *Doc) Get(path string) *yaml.Node

Get finds the node at a dotted path; [i] indexes a sequence.

func (*Doc) Origin

func (d *Doc) Origin(path string) (Origin, bool)

Origin is where the value at path comes from.

func (*Doc) Over

func (d *Doc) Over(o *Doc)

Over puts o above d: o's values win.

func (*Doc) Stamp

func (d *Doc) Stamp(n *yaml.Node, file, layer string)

Stamp records file and layer as the origin of n and every node below it that has none yet.

func (*Doc) Under

func (d *Doc) Under(o *Doc)

Under puts o below d: d's values win.

type Options

type Options struct {
	// Defaults are plugin and pack fragments, lowest first.
	Defaults []*Doc
	// Import runs one `imports:` entry and returns its fragment.
	Import func(kind, path string, project *yaml.Node) (*Doc, error)
	// NoLocal skips .rig/local.yaml.
	NoLocal bool
	// NoTemplates leaves `defaults:` and `extends` to ApplyTemplates, for a first pass that only
	// finds the plugins whose fragments may hold the templates.
	NoTemplates bool
}

Options feed Compose what lives outside rig.yaml.

type Origin

type Origin struct {
	File  string `json:"file"`
	Line  int    `json:"line"`
	Layer string `json:"layer"`
}

func (Origin) String

func (o Origin) String() string

Jump to

Keyboard shortcuts

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