discovery

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package discovery scans a configuration root and produces a stream of priority-ordered layers (base, overlays, extra overlay axes).

Index

Constants

This section is empty.

Variables

View Source
var CodecExtFunc func(ext string) string

CodecExtFunc, when non-nil, is consulted before the built-in extension table. It is wired by the top-level fastconf package to the decoder registry so that third-party RegisterCodecExt calls reach discovery without internal/discovery taking a sibling-package import dependency.

Functions

func LoadMeta

func LoadMeta(fsys fs.FS, root string) ([]byte, error)

LoadMeta 尝试从 root/_meta.yaml 加载;不存在则返回 nil, nil。

func Scan

func Scan(root string, opt ScanOptions) iter.Seq2[Layer, error]

Scan walks root and yields layers in base→overlay priority order, lexicographic within each tier.

The function returns iter.Seq2 instead of []Layer so that:

  • callers can early-stop (e.g. on a per-layer decode error);
  • large directory trees do not balloon peak memory;
  • the surface is consistent with Go 1.23+ range-over-func idioms.

Types

type ExtraOverlay

type ExtraOverlay struct {
	Dir      string // path relative to the scan root, e.g. "hosts/ua"
	Profile  string // label for provenance reporting, e.g. "host:ua"
	Priority int    // base priority for layers in this directory
}

ExtraOverlay describes an additional directory to include as file layers after the main base and overlay dirs. It is used by the multi-axis overlay feature (see ScanOptions.ExtraOverlays).

type Kind

type Kind uint8

Kind describes the merge semantics of a discovered layer. It maps one-to-one to fastconf.LayerKind; internal packages cannot import the public package without creating a cycle, hence the redefinition.

const (
	KindUnknown Kind = iota
	KindMerge
	KindPatch
)

type Layer

type Layer struct {
	Path     string
	Kind     Kind
	Profile  string
	Priority int
	Codec    string // "yaml" | "json" | "toml"; third-party codecs registered via fastconf.RegisterCodecExt show up here too (consulted through CodecExtFunc).
	Bytes    []byte
}

Layer is a descriptor emitted by the discovery stage. Bytes is read fully into memory (config files are typically less than a few MB).

type MetaFile

type MetaFile struct {
	APIVersion string   `yaml:"apiVersion"`
	Kind       string   `yaml:"kind"`
	Spec       MetaSpec `yaml:"spec"`
}

MetaFile 是 conf.d/_meta.yaml 的反序列化目标。 不存在时使用编译期默认值。Phase 2 仅消费其中字段子集;其余保留以便前向兼容。

func (*MetaFile) Apply

func (m *MetaFile) Apply(opt *ScanOptions)

Apply 把 meta 中显式字段叠加到 ScanOptions(meta 优先于代码默认值,但低于显式 Option)。

type MetaSpec

type MetaSpec struct {
	BaseDir        string   `yaml:"baseDir"`
	OverlayDir     string   `yaml:"overlayDir"`
	ProfileEnv     string   `yaml:"profileEnv"`
	DefaultProfile string   `yaml:"defaultProfile"`
	PatchSuffixes  []string `yaml:"patchSuffixes"`
	Ordering       string   `yaml:"ordering"`
	Strict         bool     `yaml:"strict"`
	AppendSlices   bool     `yaml:"appendSlices"`
	RedactEnvKeys  []string `yaml:"redactEnvKeys"`
	// MergeKeys (Phase 132) enables Kustomize-style strategic merge on
	// list-of-object slices. Each entry maps a dotted merged-tree path
	// to the field name that identifies "the same item" across overlays.
	MergeKeys map[string]string `yaml:"mergeKeys"`
}

MetaSpec mirrors the YAML schema. Apply() copies the subset that the discovery scanner needs; the framework consumes the rest separately (see ApplyManager in fastconf/manager.go).

type ScanOptions

type ScanOptions struct {
	BaseDir       string         // default "base"
	OverlayDir    string         // default "overlays"
	Profile       string         // current overlay name ("" loads base only) — legacy single-profile path
	Profiles      []string       // Active profile set; non-nil enables expression-based overlay matching.
	MatchAnd      string         // Optional global expression AND-ed with each overlay's match.
	PatchSuffixes []string       // default [".patch.yaml", ".patch.json"]
	Strict        bool           // when true, an unrecognised extension errors instead of being skipped
	FS            fs.FS          // optional virtual filesystem for tests
	ExtraOverlays []ExtraOverlay // Additional axis directories (multi-axis overlay feature).
}

ScanOptions controls scan behaviour.

Jump to

Keyboard shortcuts

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