config

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyEnvOverrides added in v0.12.0

func ApplyEnvOverrides[C any](cfg *C, name, envPrefix string, fields []EnvField[C])

ApplyEnvOverrides applies environment variable overrides to a config struct. It checks per-instance variables first (PREFIX_NAME_SUFFIX), then global variables (PREFIX_SUFFIX). Global overrides take precedence.

func LoadInstances added in v0.12.0

func LoadInstances[C any, I any](dir string, spec InstanceSpec[C, I]) ([]I, error)

LoadInstances reads configs from a .humanconfig file, applies env overrides, and builds instances using the provided spec.

func UnmarshalSection

func UnmarshalSection(dir, key string, target any) error

UnmarshalSection reads a .humanconfig YAML file from dir and unmarshals the given key into target. Returns nil when the config file is missing.

Types

type EnvField added in v0.12.0

type EnvField[C any] struct {
	Suffix string
	Set    func(c *C, v string)
}

EnvField maps a config struct field to its environment variable suffix. For example, {Suffix: "TOKEN", Set: func(c *MyConfig, v string) { c.Token = v }} will check for PROVIDER_TOKEN (global) and PROVIDER_NAME_TOKEN (per-instance).

type InstanceSpec added in v0.12.0

type InstanceSpec[C any, I any] struct {
	// Section is the YAML key in .humanconfig (e.g. "githubs", "jiras").
	Section string

	// EnvPrefix is the prefix for environment variables (e.g. "GITHUB_", "JIRA_").
	EnvPrefix string

	// EnvFields maps config struct fields to env var suffixes.
	EnvFields []EnvField[C]

	// DefaultURL is set on configs with an empty URL before env overrides.
	// Leave empty if no default (e.g. Jira requires explicit URL).
	DefaultURL string

	// GetName returns the instance name from a config entry.
	GetName func(C) string

	// SetURL sets the URL on the config. Nil if the config has no URL field.
	SetURL func(*C, string)

	// GetURL returns the URL from a config entry. Nil if the config has no URL field.
	GetURL func(C) string

	// Build creates an instance from a config entry. Return (zero, false) to skip
	// the entry (e.g. missing required credentials).
	Build func(C) (I, bool)
}

InstanceSpec defines how to load and build instances from config entries.

Jump to

Keyboard shortcuts

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