config

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 20 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 loads and edits the TOML file that lists managed servers.

Index

Constants

View Source
const (
	RestartNo        = "no"
	RestartOnFailure = "on-failure"
	RestartAlways    = "always"

	// WrapAuto (the default) detects a server's tool environment and
	// WrapNone turns detection off.
	WrapAuto = "auto"
	WrapNone = "none"
)

Restart policies.

View Source
const AutoPortBase = 3001

AutoPortBase is the first port handed out to servers without an explicit port. It is 3001 rather than 3000 because 3000 is the most contested default.

View Source
const ComposeStop = "30s"

ComposeStop is the stop timeout given to compose stacks found by discovery or imported, so containers can shut down cleanly.

Variables

View Source
var ErrConflict = errors.New("the config file changed since it was loaded; reload and try again")

ErrConflict means the file changed since the caller read it.

View Source
var ErrNotFound = errors.New("config file not found")

ErrNotFound is returned when the configuration file does not exist.

View Source
var Reserved = map[int]bool{
	3659: true, 4045: true, 5000: true, 5060: true, 5061: true, 6000: true,
	6566: true, 6665: true, 6666: true, 6667: true, 6668: true, 6669: true,
	6697: true, 7000: true, 10080: true,
}

Reserved ports are skipped by automatic assignment: 5000/7000 belong to the macOS AirPlay Receiver, the rest are on browsers' unsafe-port lists.

Functions

func AddServer

func AddServer(path string, s Spec) error

AddServer appends a new server table.

func CacheGood

func CacheGood(stateDir, path string, data []byte) error

CacheGood saves validated text with its original path for relative dirs.

func CheckRevision

func CheckRevision(path, rev string) error

CheckRevision returns ErrConflict when the file no longer has revision rev, for an edit made from a form that showed that revision.

func IsComposeCommand

func IsComposeCommand(cmd string) bool

IsComposeCommand reports whether a server's command runs a compose stack.

func IsDashboardLabel

func IsDashboardLabel(label string) bool

IsDashboardLabel reports whether label has the form of a dashboard host label.

func NewDashboardLabel

func NewDashboardLabel() string

NewDashboardLabel returns a random label that IsDashboardLabel accepts.

func Quote

func Quote(s string) string

Quote renders s as a TOML basic string.

func ReadPort

func ReadPort(path string) (int, bool, error)

ReadPort reads just the dashboard port even when server validation fails, and whether it is automatic (the file sets none), as Parse decides.

func RemoveServer

func RemoveServer(path, name string) error

RemoveServer deletes a server table and the comments directly above it.

func Render

func Render(s Spec) string

Render returns the TOML table for a server, ending with a newline.

func ReplaceIfUnchanged

func ReplaceIfUnchanged(path string, text []byte, rev string) error

ReplaceIfUnchanged writes text only if the file still has revision rev.

func Revision

func Revision(data []byte) string

Revision identifies a version of the file's text for optimistic saves.

func SetEnabled

func SetEnabled(path, name string, enabled bool) error

SetEnabled toggles a server without touching anything else in its table.

func SetKey

func SetKey(path, name, k, literal string) error

SetKey sets one key inside a server table to a TOML literal, keeping every other line (and comment) of the table untouched.

func SetTopLevel

func SetTopLevel(path, k, literal string) error

SetTopLevel sets a top-level key (outside any table) to a TOML literal.

func SpecDir

func SpecDir(root, abs string) string

SpecDir is how the absolute directory abs is written as a server's dir: relative to root when inside it ("" for root itself), otherwise with the home directory shortened to ~.

func StarterRoot

func StarterRoot() string

StarterRoot picks the directory most likely to hold the user's projects: the candidate with the most projects one or two levels down, the more conventional name winning a tie, else the home directory.

func UpdateServer

func UpdateServer(path, name string, s Spec) error

UpdateServer patches changed fields of name with s (which may carry a new name). Comment lines directly above the table are kept unless s.Comment is set.

func ValidName

func ValidName(name string) error

ValidName reports whether name can be used as a server name. Names double as DNS labels for the <name>.localhost proxy, hence the strict alphabet.

func WriteAtomic

func WriteAtomic(path string, data []byte) error

WriteAtomic replaces the file at path (or its symlink target) under the lock.

func WriteStarter

func WriteStarter(path string) error

WriteStarter creates a commented configuration file with no servers.

Types

type Config

type Config struct {
	Path string
	Root string
	Port int
	// PortAuto is true when the file sets no dashboard port, so the daemon
	// may choose another one when the default is taken (kept in the state
	// directory, see daemon.SavedPort).
	PortAuto    bool
	Shell       string
	PathPrepend []string
	Env         map[string]string
	Restore     bool
	Notify      bool
	Editor      string
	Terminal    string
	StopTimeout time.Duration
	// DockerStart is the command that starts the container engine; empty
	// means the engine behind the active Docker context is detected.
	DockerStart string
	// Share lets the owner's other devices on Tailscale connect to this daemon.
	Share   bool
	Servers []Server
	// Warnings are non-fatal problems such as duplicate ports.
	Warnings []string
}

Config is the parsed configuration file.

func Load

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

Load reads and validates the configuration at path.

func LoadAssignedPorts

func LoadAssignedPorts(path string, avoid func(port int) bool) (*Config, error)

LoadAssignedPorts loads the daemon's config and persists automatic ports under the edit lock, so later removals or reordering cannot change them. Automatic ports skip the ports avoid reports (nil avoids none), such as those of temporary servers, which the config does not list.

func LoadRecoverable

func LoadRecoverable(path, stateDir string) (*Config, error)

LoadRecoverable always returns usable settings. Its error describes the requested file, which remains editable while the last good settings run.

func Parse

func Parse(path string, data []byte) (*Config, error)

Parse validates configuration text. path is used for messages and relative paths.

func (*Config) FreePort

func (c *Config) FreePort(inUse func(int) bool) int

FreePort returns the lowest unused, unreserved port at or above AutoPortBase.

func (*Config) Groups

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

Groups returns group names in first-appearance order.

func (*Config) Resolve

func (c *Config) Resolve(targets []string) ([]string, error)

Resolve expands names and group names into server names, keeping config order.

func (*Config) Server

func (c *Config) Server(name string) (Server, bool)

Server returns the server with the given name.

func (*Config) WithDeps

func (c *Config) WithDeps(names []string) []string

WithDeps returns names plus all their transitive dependencies, ordered so that every dependency comes before its dependents.

type Duration

type Duration struct{ time.Duration }

Duration is a time.Duration written as a string such as "10s" in TOML.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

type Server

type Server struct {
	Name      string
	Dir       string // absolute
	DirRaw    string // as written in the file
	Cmd       string
	Port      int  // 0 means the server does not listen on a port
	PortAuto  bool // port was assigned automatically
	Group     string
	DependsOn []string
	Projects  []string
	Env       map[string]string
	Restart   string
	Health    string // optional HTTP path probed for readiness, e.g. "/"
	Icon      string // optional absolute icon path
	Open      string // optional path appended to the URL when opening
	// Wrap selects how the command enters the project's tool environment:
	// "" or WrapAuto detects direnv, devbox, mise or a Node version file, WrapNone runs
	// it as is, anything else is a command prefix.
	Wrap    string
	Stop    time.Duration
	StopRaw string // stop_timeout as written, "" when inherited
	IconRaw string // icon as written
	Enabled bool
	// LAN says the server is meant to be reachable from other devices, so
	// listening on the network is not pointed out.
	LAN bool
	// OnCrash is the shell command run once the server has crashed for good:
	// the server's own on_crash, else the top-level one; "" runs nothing.
	OnCrash string
}

Server is one managed dev server with defaults applied and paths resolved.

type Spec

type Spec struct {
	Name      string            `json:"name"`
	Dir       string            `json:"dir"`
	Cmd       string            `json:"cmd"`
	Port      *int              `json:"port,omitempty"`
	Group     string            `json:"group,omitempty"`
	DependsOn []string          `json:"dependsOn,omitempty"`
	Projects  []string          `json:"projects,omitempty"`
	Env       map[string]string `json:"env,omitempty"`
	Restart   string            `json:"restart,omitempty"`
	Health    string            `json:"health,omitempty"`
	Icon      string            `json:"icon,omitempty"`
	Open      string            `json:"open,omitempty"`
	Stop      string            `json:"stopTimeout,omitempty"`
	Enabled   *bool             `json:"enabled,omitempty"`
	// Comment is written as # lines above the table header.
	Comment string `json:"comment,omitempty"`
}

Spec describes a server as written to the file. Empty fields are omitted.

func SpecOf

func SpecOf(s Server) Spec

SpecOf converts a loaded server back into a Spec, keeping the original dir text.

Jump to

Keyboard shortcuts

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