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

config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config loads and validates a driftsync.yaml file — the per-project description of how to obtain the code-side spec and what to compare it against. It is the single source of truth for the `check`, `sync`, and `init` commands.

Index

Constants

View Source
const DefaultPath = "driftsync.yaml"

DefaultPath is where driftsync looks for the config when none is given.

Variables

View Source
var Stacks = []string{"fastapi", "nestjs", "spring", "huma", "swaggo", "generic"}

Stacks are the recognized `driftsync init --stack` values.

Functions

func ConfigTemplate

func ConfigTemplate(stack string) ([]byte, error)

ConfigTemplate returns the starter driftsync.yaml for a stack.

func ExampleConfigs

func ExampleConfigs() []string

ExampleConfigs lists the embedded per-stack configs, for docs/tests.

func GenspecTemplate

func GenspecTemplate() ([]byte, error)

GenspecTemplate returns the tools/genspec/main.go starter for in-process (huma) extraction. Only meaningful for --stack huma.

func WorkflowTemplate

func WorkflowTemplate(kind string) ([]byte, error)

WorkflowTemplate returns a GitHub Actions workflow: "check" or "sync".

Types

type Code

type Code struct {
	// Command is a shell snippet that writes the code-side spec to File.
	// Optional: omit it when File is already generated/committed. Chain any
	// conversion here too (e.g. swaggo's 2.0 -> 3.x step).
	Command string `yaml:"command"`
	// File is the path the code-side spec is read from after Command runs
	// (or a pre-existing file when Command is empty).
	File string `yaml:"file"`
}

Code describes how to get the OpenAPI spec your code actually produces.

type Config

type Config struct {
	Version int `yaml:"version"`
	// Published is the spec you maintain — the contract consumers see.
	Published string `yaml:"published"`
	Code      Code   `yaml:"code"`

	FailOn     FailOn `yaml:"fail_on"`
	Enrich     Enrich `yaml:"enrich"`
	Report     Format `yaml:"report"`
	ReportFile string `yaml:"report_file"`
	// SyncOutput is where `sync` writes the corrected spec. Empty = overwrite
	// Published in place.
	SyncOutput string `yaml:"sync_output"`

	// BaseDir is the directory the config lives in; every relative path above
	// is resolved against it and Command runs with it as the working directory.
	// Not a YAML field.
	BaseDir string `yaml:"-"`
	// Source is the path the config was loaded from, for error messages.
	Source string `yaml:"-"`
}

Config is a parsed, validated, path-resolved driftsync.yaml.

func Load

func Load(path string) (*Config, error)

Load reads, unmarshals, defaults, resolves, and validates a config file.

func (*Config) Output

func (c *Config) Output() string

Output is where `sync` should write the corrected published spec.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the config is internally consistent. Load calls it; the CLI calls it again after applying flag overrides.

type Enrich

type Enrich string

Enrich controls the optional LLM description step in `driftsync sync`.

const (
	EnrichAuto Enrich = "auto" // run iff an LLM API key is present (default)
	EnrichOn   Enrich = "on"   // always run (falls back to an offline stub with no key)
	EnrichOff  Enrich = "off"  // never run; new-field descriptions stay blank
)

type FailOn

type FailOn string

FailOn is the CI gate policy for `driftsync check`.

const (
	FailOnBreaking FailOn = "breaking" // exit non-zero only on BREAKING drift (default)
	FailOnAny      FailOn = "any"      // exit non-zero on any drift at all
	FailOnNever    FailOn = "never"    // always exit zero (report only)
)

type Format

type Format string

Format is the drift-report rendering.

const (
	FormatText Format = "text" // terminal-style (default)
	FormatMD   Format = "md"   // GitHub-flavored markdown, for a PR body
	FormatJSON Format = "json" // machine-readable
)

Jump to

Keyboard shortcuts

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