config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config assembles the settings a Wegweiser process starts with.

It holds bootstrap settings and nothing else: listen addresses, where the database is, and how loudly to log. Everything an operator manages (zones, records, tokens, the reverse conflict policy) lives in the database and is reachable through the API, because architecture invariant 1 says no feature exists in only one client, and a setting that lives only in a file is a feature that exists only for whoever can log in to the machine (docs/decisions/ D11).

Index

Constants

View Source
const DefaultPath = "/etc/wegweiser/config.yaml"

DefaultPath is where the file lives when nothing says otherwise. It matches the packaging: the unit and the container both put it there.

View Source
const PathEnv = "WEG_CONFIG"

PathEnv names the environment variable that moves the file.

Variables

View Source
var Defaults = struct {
	DNSListen       string
	APIListen       string
	APIUI           bool
	Database        string
	UDPResponseSize uint16
	MaxTCPClients   int
	MaxTransfers    int
	LogLevel        string
	ClusterListen   string
}{

	DNSListen: ":53",

	APIListen: "127.0.0.1:8053",

	APIUI: true,

	Database:        "wegweiser.db",
	UDPResponseSize: 1232,

	MaxTCPClients: 0,
	MaxTransfers:  0,
	LogLevel:      "info",

	ClusterListen: ":8054",
}

Defaults are what a process runs with when nothing says otherwise.

View Source
var LogLevels = []string{"debug", "info", "warn", "error"}

LogLevels are the levels Config.LogLevel accepts.

Functions

func LocalAPIAddress

func LocalAPIAddress() (string, bool)

LocalAPIAddress is where the API on this machine listens, as far as the configuration file says, and whether the file said anything.

Types

type APIFile

type APIFile struct {
	Listen *string `json:"listen,omitempty"`
	UI     *bool   `json:"ui,omitempty"`
}

APIFile is what the control plane takes.

type Cluster added in v0.5.0

type Cluster struct {
	// ID is the identifier the file names, empty when it names none and one
	// is minted on first start.
	ID        Value[string]
	Listen    Value[string]
	Advertise Value[string]
	// Secret is the shared secret, decoded. Whether it is long enough is the
	// transport's to say, which names the rule it enforces.
	Secret []byte
	// Dir is where Raft keeps its log and its snapshots, beside the database
	// and named after it. Repairing a member means removing both
	// (docs/decisions/d29-a-node-that-cannot-apply.md).
	Dir string
}

Cluster is how this node takes part in a cluster. It is read from the file only: a secret belongs in a file only root can read, and the rest is only ever set next to it.

type ClusterFile added in v0.5.0

type ClusterFile struct {
	ID        *string `json:"id,omitempty"`
	Listen    *string `json:"listen,omitempty"`
	Advertise *string `json:"advertise,omitempty"`
	Secret    *string `json:"secret,omitempty"`
}

ClusterFile is what a node needs to be reachable as a cluster member, and nothing about who the other members are: that list lives in the log (docs/decisions/d42-membership-lives-in-the-log.md).

type Config

type Config struct {
	// Path is the file that was read, empty when there was none.
	Path string

	DNSListen       Value[string]
	APIListen       Value[string]
	APIUI           Value[bool]
	Database        Value[string]
	UDPResponseSize Value[uint16]
	MaxTCPClients   Value[int]
	MaxTransfers    Value[int]
	LogLevel        Value[string]

	// Cluster is nil unless the file has a cluster section. Without one the
	// node is a single server, exactly as it was before clusters existed.
	Cluster *Cluster
}

Config is the settings a process starts with.

func Load

func Load(path string, flags Flags) (*Config, error)

Load reads the file and lays the environment and the flags over it.

type DNSFile

type DNSFile struct {
	Listen          *string `json:"listen,omitempty"`
	UDPResponseSize *uint16 `json:"udpResponseSize,omitempty"`
	MaxTCPClients   *int    `json:"maxTCPClients,omitempty"`
	MaxTransfers    *int    `json:"maxTransfers,omitempty"`
}

DNSFile is what the query path takes.

type DatabaseFile

type DatabaseFile struct {
	Path *string `json:"path,omitempty"`
}

DatabaseFile is where the store lives.

type File

type File struct {
	DNS      DNSFile      `json:"dns,omitempty"`
	API      APIFile      `json:"api,omitempty"`
	Database DatabaseFile `json:"database,omitempty"`
	Log      LogFile      `json:"log,omitempty"`
	Cluster  ClusterFile  `json:"cluster,omitempty"`
}

File is the document on disk.

type Flags

type Flags struct {
	DNSListen       *string
	APIListen       *string
	APIUI           *bool
	Database        *string
	UDPResponseSize *uint16
	MaxTCPClients   *int
	MaxTransfers    *int
	LogLevel        *string
}

Flags are the settings a command line supplied. A nil field is one the command line did not mention.

type LogFile

type LogFile struct {
	Level *string `json:"level,omitempty"`
}

LogFile is how loudly to report.

type Source

type Source string

Source is where a setting's value came from.

const (
	FromFlag        Source = "flag"
	FromEnvironment Source = "environment"
	FromFile        Source = "file"
	FromDefault     Source = "default"
)

The four places a setting can come from, strongest first.

type Value

type Value[T any] struct {
	Value  T
	Source Source
}

Value is one setting, and where it came from.

Jump to

Keyboard shortcuts

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