consul

package module
v0.0.0-...-dc1cc61 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package consul resolves gostructor fields from a HashiCorp Consul KV prefix. Each field maps to a key under the prefix; the key is the field's per-source override (`cfg:"host,consul:database/host"`) or, lacking one, its base name.

It implements gostructor.Watchable using Consul blocking queries: a single long-poll on the prefix returns as soon as any key under it changes, so a reload fires promptly without busy polling. An optional snapshot store (gostructor/snapshot) keeps the last-known-good KV set so the app still starts when Consul is unreachable.

Index

Constants

View Source
const DefaultName = "consul"

DefaultName is this source's identity and cfg per-source override key.

View Source
const DefaultWaitTime = 5 * time.Minute

DefaultWaitTime bounds a single blocking query; Consul returns earlier the moment a key changes. It also caps how long Watch takes to notice its context was cancelled between queries.

Variables

This section is empty.

Functions

func New

func New(opts Options) (*source, error)

New returns a Consul-backed gostructor.Source (also a gostructor.Watchable). The client is built lazily on first use, so constructing a source never blocks; connection problems surface at fill time (or trigger a snapshot fallback).

Types

type Options

type Options struct {
	// Address is the Consul HTTP address (host:port). Empty uses the api
	// defaults (CONSUL_HTTP_ADDR, else 127.0.0.1:8500).
	Address string
	// Prefix is the KV path fields are read from, e.g. "config/orders". A field
	// key is joined onto it with "/".
	Prefix string
	// Token is the optional ACL token (empty uses CONSUL_HTTP_TOKEN if set).
	Token string
	// Datacenter optionally targets a non-default datacenter.
	Datacenter string
	// WaitTime bounds one blocking query; zero uses DefaultWaitTime.
	WaitTime time.Duration
	// Snapshot, if set, stores each good KV read and is served when Consul is
	// unreachable at startup.
	Snapshot snapshot.Store
	// Name overrides the source identity (DefaultName otherwise).
	Name string
	// Logger receives watch/fallback diagnostics; nil discards them.
	Logger *slog.Logger
}

Options configures a consul Source.

Jump to

Keyboard shortcuts

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