Third-party driver for gocloud.dev/runtimevar to read from Consul KV.
| Driver | Backend | Import |
|---|---|---|
consulvar |
HashiCorp Consul KV | github.com/peczenyj/runtimevar-consul/consulvar |
import (
"context"
"fmt"
_ "github.com/peczenyj/runtimevar-consul/consulvar" // registers the consul:// scheme
"gocloud.dev/runtimevar"
)
func main() {
ctx := context.Background()
v, err := runtimevar.OpenVariable(ctx, "consul://services/auth/db_url?decoder=string")
if err != nil { panic(err) }
defer v.Close()
snap, err := v.Latest(ctx)
if err != nil { panic(err) }
fmt.Println(snap.Value.(string))
}The opener reads Consul connection info from the standard environment variables (CONSUL_HTTP_ADDR, CONSUL_HTTP_TOKEN, …) via api.DefaultConfig(). For more control, construct a *consul/api.Client yourself and call consulvar.OpenVariable(client, key, opts).
Install the toolchain:
go install gotest.tools/gotestsum@latest
# golangci-lint v2 — see https://golangci-lint.run/welcome/install/#local-installation
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.12.2
go install github.com/vektra/mockery/v2@latest # only needed to regenerate mocks
# task: https://taskfile.dev/installation/
# git-cliff: https://git-cliff.org/docs/installationRequires Go 1.25 or newer (the go directive in go.mod).
Common commands (the Makefile delegates to task):
task ci # full pre-push gate: tidy:check + lint + build + unit + integration
task test # unit tests
task test:integration # unit + integration (requires Docker)
task lint
task format
task changelog:unreleasedRun task ci before pushing — it mirrors the GitHub Actions checks. Both CI and task ci run on whatever Go toolchain is installed; the minimum supported version is recorded by the go directive in go.mod and is not otherwise enforced.
This repo follows Conventional Commits so git cliff can generate Keep a Changelog sections. Use feat:, fix:, chore:, docs:, test:, ci:, build: prefixes.
develis the integration branch. All PRs targetdevel.mainholds release commits only; tagsvX.Y.Zare cut onmain.
Releases use git-flow (AVH).
The repository is configured with main as the production branch, devel as
the development branch, and v as the version-tag prefix; release.finish.push
is enabled, so finishing a release pushes main, devel, and the tag.
# 1. preview the upcoming changelog section
task changelog:unreleased
# 2. start the release off devel (omit the leading v; the tag is prefixed for you)
git flow release start X.Y.Z
# 3. regenerate the changelog on the release branch and commit it
task changelog -- --tag vX.Y.Z
git commit -am "chore: update changelog for vX.Y.Z"
# 4. finish: merge into main, tag vX.Y.Z, back-merge into devel, push all three
git flow release finish X.Y.ZThe release.yml workflow, triggered by the vX.Y.Z tag, then publishes the
GitHub Release with a source archive, SHA256SUMS, and signed SLSA build
provenance. Verify a release as described in SECURITY.md.
MIT — see LICENSE.