Skip to content

peczenyj/runtimevar-consul

runtimevar-consul

tag Go Version GoDoc CI codecov Report card CodeQL Dependency Review SLSA Build L2 License Latest release GitHub Release Date Last commit PRs Welcome

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

Quick start — 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).

Development

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/installation

Requires 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:unreleased

Run 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.

Commit messages

This repo follows Conventional Commits so git cliff can generate Keep a Changelog sections. Use feat:, fix:, chore:, docs:, test:, ci:, build: prefixes.

Branching

  • devel is the integration branch. All PRs target devel.
  • main holds release commits only; tags vX.Y.Z are cut on main.

Releasing

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.Z

The 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.

License

MIT — see LICENSE.

About

Third-party gocloud.dev/runtimevar driver for HashiCorp Consul KV — watch config values with the Go CDK API

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors