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

yamlconf

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package yamlconf loads YAML configuration and keeps track of where every key came from.

Both of rig's configuration formats — the project file and the per-table files — are validated against a JSON Schema generated from their Go structs, and both report problems at the exact line and column of the offending key. That machinery lives here so the two cannot drift apart in how strictly they read a file or how precisely they report a mistake.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Join

func Join(segments ...string) string

Join builds a path from segments, skipping empty ones.

Types

type Format

type Format struct {
	// ID is the schema's $id, for example "https://rig.dev/schema/table.v1.json".
	ID string
	// Title and Description document the format in the emitted schema.
	Title       string
	Description string
	// New returns a fresh zero value of the format's root struct. It is called
	// both to reflect the schema and to decode into.
	New func() any
	// contains filtered or unexported fields
}

Format describes one configuration file format: the Go struct that defines it, and the identity its JSON Schema publishes itself under.

The schema is generated once and reused for two purposes — written to disk for editors, and compiled as the validator. One schema, so what an editor accepts and what rig accepts cannot diverge.

func (*Format) Decode

func (f *Format) Decode(path string, data []byte, target any) (ix *Index, ok bool, diags diag.List)

Decode parses, validates, and decodes a configuration file into target.

It returns the anchor index whenever the YAML parsed, even if validation failed, so a caller can still report positions for problems it finds itself. ok is false when target was not populated.

func (*Format) Schema

func (f *Format) Schema() ([]byte, error)

Schema returns the JSON Schema for the format, indented for writing to disk.

type Index

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

Index maps a dotted path within a configuration file to the position of the key that declares it.

Paths use the shape "columns.title.comment" for mappings and "endpoints.0.name" for sequences, which is also how schema violations report their location, so the two line up without translation.

func BuildIndex

func BuildIndex(file string, doc ast.Node) *Index

BuildIndex walks a parsed document and records where every key sits.

func (*Index) At

func (ix *Index) At(path string) diag.Anchor

At returns the anchor for a path.

When the exact path is not in the file — a missing required key, say — the lookup walks up to the nearest ancestor that is. Pointing at the enclosing key is far more useful than pointing at line 1, and it is what a reader expects: the problem is *in* that block.

func (*Index) File

func (ix *Index) File() string

File returns the path of the file this index describes.

func (*Index) Has

func (ix *Index) Has(path string) bool

Has reports whether the exact path appears in the file. Callers use it to tell "set to the zero value" from "not set at all".

Jump to

Keyboard shortcuts

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