config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 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 config resolves the bootstrap settings of `bubbles serve` from flags and BUBBLES_* environment variables, prepares the data directory and enforces single-instance and bind policy. Everything else the server needs lives in the settings table, not here.

Index

Constants

View Source
const (
	DefaultHTTPSAddr = ":28225"
	DefaultHTTPAddr  = ":28226"
	DefaultMDNSName  = "bubbles"
)

Default listen addresses and mDNS host name.

View Source
const (
	DirFiles   = "files"
	DirTmp     = "tmp"
	DirTLS     = "tls"
	DirLogs    = "logs"
	DirBackups = "backups"
)

Subdirectories of the data directory that EnsureDataDir creates.

View Source
const (
	DirMode  os.FileMode = 0o700
	FileMode os.FileMode = 0o600
)

Permissions for data directory contents on Unix. On Windows the protected DACL set by EnsureDataDir plays this role.

View Source
const LockFileName = "bubbles.lock"

LockFileName is the single-instance lock inside the data directory.

Variables

View Source
var ErrLocked = errors.New("data directory is locked by a running bubbles server")

ErrLocked means another process already holds the data directory. The CLI maps it to exit code 3. Test with errors.Is.

View Source
var ErrNoPrivateAddress = errors.New("no private LAN address found on this host: bubbles serves private networks only; " +
	"connect to a LAN or pass --allow-public (BUBBLES_ALLOW_PUBLIC=1) to start anyway")

ErrNoPrivateAddress is returned by Config.CheckBindPolicy when the host has no private LAN address and --allow-public was not given.

Functions

func EnsureDataDir

func EnsureDataDir(dir string) error

EnsureDataDir creates dir and its subdirectories (files, tmp, tls, logs, backups) readable by the owner only: mode 0700 on Unix, a protected DACL granting SYSTEM, Administrators and the current user on Windows. It is safe to call repeatedly.

func EnvName

func EnvName(flagName string) string

EnvName returns the environment variable that mirrors a flag, for example "data-dir" becomes BUBBLES_DATA_DIR.

func WriteUsage

func WriteUsage(w io.Writer, opts Options)

WriteUsage prints the serve flags, their defaults and environment names.

Types

type Config

type Config struct {
	DataDir     string   `json:"data_dir"`
	HTTPSAddr   string   `json:"https_addr"`
	HTTPAddr    string   `json:"http_addr"`
	MDNSName    string   `json:"mdns_name"`
	NoMDNS      bool     `json:"no_mdns"`
	TLSCert     string   `json:"tls_cert"`
	TLSKey      string   `json:"tls_key"`
	TLSExtraDNS []string `json:"tls_extra_dns"`
	AllowPublic bool     `json:"allow_public"`
	PrintConfig bool     `json:"print_config"`
}

Config holds the resolved `bubbles serve` settings.

func Parse

func Parse(args []string, opts Options) (Config, error)

Parse resolves the configuration for `bubbles serve`. Precedence, highest first: command-line flag, BUBBLES_* environment variable, built-in default. It prints nothing; it returns flag.ErrHelp when -h/--help was requested (see WriteUsage).

func (Config) CheckBindPolicy

func (c Config) CheckBindPolicy(privateAddrs []netip.Addr) error

CheckBindPolicy enforces the LAN-only policy: with no private LAN address (privateAddrs is the ranked list from netutil) the server refuses to start unless AllowPublic is set.

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock holds the exclusive single-instance lock on a data directory. The operating system drops it if the process dies, so a crash never leaves a stale lock behind.

func AcquireLock

func AcquireLock(dataDir string) (*Lock, error)

AcquireLock takes the exclusive lock on <dataDir>/bubbles.lock, creating the file (mode 0600) if needed. It does not block: if another holder exists it returns an error wrapping ErrLocked. The data directory must exist.

func (*Lock) Release

func (l *Lock) Release() error

Release drops the lock. The lock file itself is left in place. Calling it on a nil or already released Lock is a no-op.

type Options

type Options struct {
	// Getenv looks up environment variables; nil means os.Getenv.
	Getenv func(string) string
	// AsService selects the machine-wide default data directory used when the
	// server runs as an OS service.
	AsService bool
}

Options are the inputs to Parse besides the arguments.

Jump to

Keyboard shortcuts

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