Skip to content

feat(config): exported strict Decode + ApplyDefaults for embedding AppConfig #8

Open

Description

@devops-bda

Context

xpro-ee (private; it builds on xpro-oss as a Go module) needs a config file that is a superset of config.AppConfig, with extra top-level keys for NATS, the watcher, licensing and so on. Right now config.Load decodes into AppConfig with KnownFields(true), so any extra key is rejected. Because expandStrings/expandEnv and the defaulting are unexported, a downstream module would have to copy them. The change itself is generic: it lets any embedding program reuse xpro-oss's strict decode, env expansion and defaults.

Requested by xpro-ee, epic U (see the xpro-ee Roadmap tracker).

Reference behaviour (xpro — read only, do not copy)

  • xpro/internal/config/config.go:247 runs os.ExpandEnv on the raw YAML text before parsing, so a ${VAR} value containing :, quotes or newlines can rewrite the document. Do not carry this over. xpro-oss's expand-after-parse is the right model, and this issue only exposes it.

Plugs into xpro-oss

  • config.Load, expandStrings, expandEnv, and the defaults block inside Load.

Scope

  • func Decode(r io.Reader, v any) error: strict YAML decode (KnownFields(true), empty document OK), then ${VAR} expansion over every string and *string reachable from v.
  • func (c *AppConfig) ApplyDefaults(): the current defaults (Source.Type="local", Target.DB="postgres", Workers=8), moved out of Load.
  • Rewrite Load on top of Decode + ApplyDefaults. Behaviour must not change.
  • The doc comment shows the intended embedding:
    type EEConfig struct {
        config.AppConfig `yaml:",inline"`
        NATS NATSConfig  `yaml:"nats"`
    }

Out of scope

  • No new config keys, and nothing EE-specific.

Acceptance criteria

  • A struct embedding AppConfig with yaml:",inline" plus its own fields decodes through Decode. Unknown keys are still rejected at both levels.
  • ${VAR} expansion reaches the embedded fields, the outer struct's fields, slices and *string.
  • All existing config tests pass unchanged, and new tests cover Decode and ApplyDefaults.
  • go vet, gofmt -l, go test -race, golangci-lint, govulncheck clean.
  • AGENTS.md/CLAUDE.md config row mentions Decode for embedding.

Security notes

  • None. Keep expand-after-parse; never expand raw text.

Depends on: none

Activity

  1. added
    upstream
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions