config

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config defines the vuego-cli configuration file format.

A configuration file declares the virtual hosts a single vuego-cli process serves. Each entry binds a DNS host name to a content folder and the mode used to render it, which lets one process sit behind a reverse proxy and serve several documentation sites from one folder tree.

vhost:
  - domain: docs.example.com
    path: ./content/docs
    mode: docs
  - domain: tour.example.com
    path: ./content/vuego-tour
    mode: tour

Index

Constants

This section is empty.

Variables

View Source
var DefaultFilenames = []string{"vuego-cli.yml", "vuego-cli.yaml"}

DefaultFilenames lists the configuration files looked up by Find, in order.

View Source
var ErrNotFound = errors.New("no configuration file found")

ErrNotFound is returned by Find when no default configuration file exists.

Functions

func Find

func Find(dir string) (string, error)

Find returns the path of the first default configuration file present in dir. It returns ErrNotFound when none of DefaultFilenames exists.

func FindFS

func FindFS(fsys fs.FS) (string, error)

FindFS returns the name of the first default configuration file present in fsys. It returns ErrNotFound when none of DefaultFilenames exists.

func NormalizeHost

func NormalizeHost(host string) string

NormalizeHost reduces a host name to the form used for matching: lower case, without a port, and without the trailing dot of a fully qualified name. IPv6 literals keep their brackets.

Types

type Config

type Config struct {
	// Addr is the address the HTTP server listens on. When empty the
	// command line default applies.
	Addr string `yaml:"addr"`

	// TrustForwardedHost routes by the X-Forwarded-Host header when it is
	// present, for proxies that rewrite Host on the way through. Leave it
	// off unless the process is only reachable through such a proxy: any
	// client that can reach the server can set the header.
	TrustForwardedHost bool `yaml:"trust_forwarded_host"`

	// VHosts are the virtual hosts this process serves.
	VHosts []VHost `yaml:"vhost"`
}

Config is the vuego-cli configuration document.

func Decode

func Decode(data []byte) (*Config, error)

Decode parses a configuration document without resolving paths or validating it. Load is the usual entry point; Decode exists for callers that supply the document from somewhere other than the filesystem.

func Load

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

Load reads, decodes and validates the configuration file at path. Relative vhost paths are resolved against the directory holding the file, so a configuration is independent of the process working directory.

func LoadFS

func LoadFS(fsys fs.FS, name string, base string) (*Config, error)

LoadFS reads, decodes and validates the configuration file named name in fsys. Relative vhost paths are resolved against base, which is the directory the configuration is considered to live in.

func (*Config) Resolve

func (c *Config) Resolve(base string)

Resolve rewrites relative vhost paths so they are anchored at base, and normalizes domain names for matching. It is idempotent.

func (*Config) Validate

func (c *Config) Validate() error

Validate reports the first problem found in the configuration document. It checks the document only and does not touch the filesystem; whether a vhost's path exists is settled when its content filesystem is opened.

A configuration with no vhost entries is an error: an empty file is a mistake, and the caller falls back to serving the working directory only when no file exists at all.

type Mode

type Mode string

Mode selects the server implementation used for a virtual host.

const (
	// ModeDocs renders a markdown documentation tree with the basecoat theme.
	ModeDocs Mode = "docs"

	// ModeTour renders a tour: numbered chapter files split into lessons.
	ModeTour Mode = "tour"

	// ModeServe is the development server: vuego templates, LESS stylesheets
	// and static files served straight from the folder.
	ModeServe Mode = "serve"
)

The available modes. Each corresponds to an existing vuego-cli command.

func Modes

func Modes() []Mode

Modes returns every valid mode.

func (Mode) String

func (m Mode) String() string

String returns the mode as written in the configuration file.

func (Mode) Valid

func (m Mode) Valid() bool

Valid reports whether the mode is one returned by Modes.

type VHost

type VHost struct {
	// Domain is the host name matched against the request. Matching is
	// case insensitive and ignores the port.
	Domain string `yaml:"domain"`

	// Path is the folder served for this domain. It is the full content
	// root: point it at the nested folder if the documents do not live at
	// the top of a checkout. Relative paths resolve against the directory
	// holding the configuration file.
	Path string `yaml:"path"`

	// Mode selects the server: docs, tour or serve.
	Mode Mode `yaml:"mode"`
}

VHost binds a domain name to a content folder and a rendering mode.

Jump to

Keyboard shortcuts

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