config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config loads and validates datavase's YAML configuration.

Parsing is deliberately split from file access: Parse works on any io.Reader so the whole validation surface can be tested without touching the filesystem.

Index

Constants

View Source
const (
	DefaultPort       = 3306
	DefaultTunnelPort = 22
	DefaultAutoLimit  = 1000
	DefaultFetchChunk = 500
	DefaultBufferMax  = 50000
)

Default values applied when the corresponding key is absent.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the configuration file location, honouring XDG_CONFIG_HOME when it is set.

Types

type Config

type Config struct {
	DataSources []DataSource `yaml:"datasources"`
	Defaults    Defaults     `yaml:"defaults"`

	// Keymap chooses the keyboard preset and overrides individual bindings.
	// See the Keymap type for the accepted forms.
	Keymap Keymap `yaml:"keymap"`
}

Config is the root of the configuration file.

func Load

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

Load reads and validates the configuration file at path.

func Parse

func Parse(r io.Reader) (*Config, error)

Parse reads and validates YAML configuration from r.

Unknown keys are rejected rather than ignored: a typo such as "hots" would otherwise surface much later as a confusing "host is required".

func (*Config) Find

func (c *Config) Find(name string) (*DataSource, error)

Find returns the datasource with the given name.

func (*Config) Names

func (c *Config) Names() []string

Names lists the configured datasource names in file order.

type DataSource

type DataSource struct {
	Name     string  `yaml:"name"`
	Env      Env     `yaml:"env"`
	Host     string  `yaml:"host"`
	Port     int     `yaml:"port"`
	User     string  `yaml:"user"`
	Database string  `yaml:"database"`
	Tunnel   *Tunnel `yaml:"tunnel"`
}

DataSource is a single MySQL/MariaDB target. Passwords are never stored here; they live in the OS keychain keyed by Name.

type Defaults

type Defaults struct {
	AutoLimit  int `yaml:"auto_limit"`
	FetchChunk int `yaml:"fetch_chunk"`
	BufferMax  int `yaml:"buffer_max"`
}

Defaults holds tunables shared by every datasource.

type Env

type Env string

Env labels how dangerous a datasource is. The guard package keys its policy off this value, so an unrecognised label must never silently degrade into a permissive one.

const (
	EnvProd  Env = "prod"
	EnvStage Env = "stage"
	EnvDev   Env = "dev"
)

type Keymap

type Keymap struct {
	// Preset names the keyboard to start from; empty means the default.
	Preset string `yaml:"preset"`
	// Actions overrides individual bindings by action name.
	Actions map[string][]string `yaml:"actions"`
}

Keymap is the keyboard section of the configuration.

It carries values only. Preset names and binding syntax are the keymap package's to validate, which is what keeps configuration free of any knowledge of what a key does.

func (*Keymap) UnmarshalYAML

func (k *Keymap) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML reads both spellings of the section.

The section began life as a bare action-to-keys mapping:

keymap:
  run: ["ctrl+enter", "f5"]

and gained a preset later:

keymap:
  preset: vim
  actions:
    run: ["f5"]

Both are accepted. Rejecting the older form would silently stop applying the keys of anyone already using it, which is worse than failing to load — they would find out by pressing a key and getting nothing.

type Tunnel

type Tunnel struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Identity string `yaml:"identity"`
}

Tunnel describes an SSH bastion to reach a datasource through.

Jump to

Keyboard shortcuts

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