consul

command
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

Optional Consul layer

Load config.yaml first, optionally pull a YAML value from Consul KV, then apply EDGE_* environment variables (highest precedence).

When CONSUL_HTTP_ADDR is not set, WithIf turns the Consul source into a no-op -- the program still runs using file and environment only.

Run (without Consul)

cd examples/consul && go run .

Run (with Consul)

Point CONSUL_HTTP_ADDR to a running Consul agent and make sure the KV path exists:

export CONSUL_HTTP_ADDR=http://127.0.0.1:8500
cd examples/consul && go run .

Adjust the KV path in main.go (synthra/example/config.yaml) to match your cluster.

Tests

No live Consul is required -- the tests only exercise the file + env path:

cd examples/consul && go test -v

Key ideas

  1. Conditional sources -- WithIf(condition, option) adds a source only when the condition is true.
  2. Graceful degradation -- the program works with or without Consul.
  3. Same merge order -- Consul sits between file and env, so environment variables still win.

Documentation

Overview

Package main loads local YAML, optionally merges Consul KV, then env.

When CONSUL_HTTP_ADDR is unset, WithIf adds no Consul source and the program still runs using file + environment only.

Jump to

Keyboard shortcuts

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