engineconfig

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 2 modules, 1 package

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 engineconfig implements the reference loader for protowire project-level engine configuration (RFC-001 §9.4).

A project's engine selection and engine-level knobs live in a single protowire.config.textproto file — a text-format protowire.schema.config.v1.EngineConfig message — at the project root. This package is the shared implementation of the discovery and precedence rules, so that protocheck, protolsp, and CLI tooling all resolve the same effective configuration:

  • Discovery walks upward from the working directory (or an explicit schema root) to the filesystem root; the nearest config file wins. There is no merging or cascading between nested configs.
  • Precedence, highest first: per-setting CLI flags (Overrides), an explicit config path (--config), the PROTOWIRE_CONFIG environment variable (a pointer to a file, never inline settings), the discovered file, and finally built-in defaults.

Malformed configuration is a hard error: an unreadable or unparseable file, an invalid execution mode, or a configured engine name missing from Options.KnownEngines fails loading outright — there is no fallback to defaults and no partial load. The `engine` field itself is reserved (RFC-001 §9.4, protowire#282): the expression language is fixed by §5.4, so nothing selects an engine and no default exists.

Index

Constants

View Source
const (
	// FileName is the name of the engine configuration file that
	// discovery looks for: a text-format
	// protowire.schema.config.v1.EngineConfig message.
	FileName = "protowire.config.textproto"

	// EnvVar is the environment variable that points at an engine
	// configuration file. It is a file pointer only — it never carries
	// inline settings — and is consulted only when no explicit config
	// path is given.
	EnvVar = "PROTOWIRE_CONFIG"

	// DefaultEngine is what Engine resolves to when no configuration
	// source sets one: nothing. RFC-001 §9.4 reserved the `engine` field
	// on 2026-09-07 (protowire#282) — the expression language is fixed
	// by §5.4, so no engine selection exists — and retired the former
	// "cel" default with it. Kept as an exported constant so callers
	// that compare against it keep compiling.
	DefaultEngine = ""

	// DefaultMaxRecursionDepth is the normative default for
	// max_recursion_depth (RFC-001 §6.4). A configured value of 0 means
	// this default.
	DefaultMaxRecursionDepth = 64
)

Variables

This section is empty.

Functions

func Discover

func Discover(dir string) (string, error)

Discover walks upward from dir (defaulting to the current working directory) to the filesystem root and returns the path of the nearest protowire.config.textproto, or "" if there is none. Nested configurations do not merge or cascade — the nearest file wins, full stop.

Types

type Config

type Config struct {
	// FunctionLibraries lists import paths (resolved like proto imports)
	// of schema files whose function declarations the engine must
	// implement (RFC-001 §9.2, §9.3).
	FunctionLibraries []string
	// CatalogLibraries lists locale catalog source files registered with
	// the engine for i18n message rendering: text-format
	// protowire.schema.catalog.v1.Catalog files, one locale each, with
	// relative paths resolved against the config file's directory
	// (RFC-001 §7). The catalogs package is the reference loader.
	CatalogLibraries []string
	// Engine is the registered engine identifier, e.g. "cel",
	// "starlark", "go".
	Engine string
	// Path is the configuration file the non-default settings came from.
	// It is empty when Source is [SourceDefaults].
	Path string
	// Source is the precedence tier that supplied Path.
	Source Source
	// DefaultMode is the execution mode used when a caller of Validate()
	// does not choose one.
	DefaultMode ExecutionMode
	// MaxRecursionDepth is the maximum message-nesting depth validated
	// (RFC-001 §6.4).
	MaxRecursionDepth uint32
	// StrictValidation makes missing function implementations fail
	// engine startup instead of failing at first call (RFC-001 §9.2).
	StrictValidation bool
}

Config is an effective engine configuration: the result of resolving every precedence tier and normalizing field-level defaults. It mirrors protowire.schema.config.v1.EngineConfig, except that Engine is never empty, DefaultMode is never ExecutionModeUnspecified, and MaxRecursionDepth is never 0.

func Load

func Load(opts Options) (*Config, error)

Load resolves the effective engine configuration per RFC-001 §9.4.

The configuration file is selected by precedence: opts.ConfigPath if set, else the file named by the PROTOWIRE_CONFIG environment variable if set, else the nearest protowire.config.textproto found by walking upward from opts.Dir. If none is found, built-in defaults apply. opts.Flags then overrides individual settings, and field-level defaults are normalized (empty engine → "cel", unspecified mode → collect-all, zero depth → 64).

type ExecutionMode

type ExecutionMode int32

ExecutionMode is the default execution mode for validation, mirroring protowire.schema.v1.ExecutionMode value-for-value.

const (
	// ExecutionModeUnspecified is the zero value; it means
	// [ExecutionModeCollectAll] (RFC-001 §6.4). [Load] never returns it:
	// the effective configuration is normalized to a concrete mode.
	ExecutionModeUnspecified ExecutionMode = 0
	// ExecutionModeCollectAll collects every violation before returning.
	ExecutionModeCollectAll ExecutionMode = 1
	// ExecutionModeFailFast stops at the first violation.
	ExecutionModeFailFast ExecutionMode = 2
)

func (ExecutionMode) String

func (m ExecutionMode) String() string

String returns the protowire.schema.v1.ExecutionMode name for m.

type Options

type Options struct {
	// Flags carries per-setting CLI flag overrides, applied on top of
	// whichever configuration file (or defaults) wins.
	Flags Overrides
	// KnownEngines lists the engine identifiers registered with the
	// calling tool. When non-nil and a configuration source sets an
	// engine name, a name outside the list is a hard error. Since
	// RFC-001 §9.4 reserved the field (protowire#282) no source has to
	// set one, and an unset name passes any registry: there is no
	// default to check. When nil, the caller resolves the name itself.
	KnownEngines []string
	// Dir is the directory discovery starts from: the working directory
	// or an explicit schema root. It defaults to the current working
	// directory. It is ignored when ConfigPath or the PROTOWIRE_CONFIG
	// environment variable selects a file explicitly.
	Dir string
	// ConfigPath is an explicit configuration file path (--config). When
	// set it is loaded directly, skipping the environment variable and
	// discovery; a missing or malformed file is a hard error.
	ConfigPath string
}

Options configures Load.

type Overrides

type Overrides struct {
	// FunctionLibraries replaces the configured function_libraries when
	// non-nil. A non-nil empty slice overrides to no libraries.
	FunctionLibraries []string
	// CatalogLibraries replaces the configured catalog_libraries when
	// non-nil. A non-nil empty slice overrides to no libraries.
	CatalogLibraries []string
	// Engine replaces the configured engine when non-nil.
	Engine *string
	// StrictValidation replaces the configured strict_validation when
	// non-nil.
	StrictValidation *bool
	// DefaultMode replaces the configured default_mode when non-nil.
	DefaultMode *ExecutionMode
	// MaxRecursionDepth replaces the configured max_recursion_depth when
	// non-nil. 0 means the normative default,
	// [DefaultMaxRecursionDepth].
	MaxRecursionDepth *uint32
}

Overrides carries per-setting CLI flag values — the highest precedence tier. A nil field means the flag was not set and the underlying configuration value is kept.

type Source

type Source int

Source identifies which precedence tier supplied the configuration file that Config was loaded from. Per-setting flag overrides apply on top of any tier and do not change the source.

const (
	// SourceDefaults means no configuration file was found or given; the
	// configuration is the built-in defaults.
	SourceDefaults Source = iota
	// SourceDiscovered means the file was found by walking upward from
	// the starting directory.
	SourceDiscovered
	// SourceEnv means the file was named by the PROTOWIRE_CONFIG
	// environment variable.
	SourceEnv
	// SourceFlag means the file was named by an explicit config path
	// ([Options].ConfigPath, i.e. --config).
	SourceFlag
)

func (Source) String

func (s Source) String() string

String returns a human-readable name for s.

Jump to

Keyboard shortcuts

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