host

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAddr = ":8080"

DefaultAddr is the address used when neither the command line nor the configuration file names one.

View Source
const Name = "Serve multiple sites by domain from a config file"

Name is the command title.

Variables

This section is empty.

Functions

func DirFS

func DirFS(path string) (fs.FS, error)

DirFS opens a vhost path as a directory on disk, reporting a path that is missing or is not a directory.

func New

func New() *cli.Command

New creates a new host command.

func Serve

func Serve(ctx context.Context, addr string, configPath string) error

Serve starts the virtual hosting server. An empty configPath looks for a default configuration file in the current directory and falls back to serving that directory when none is found. An empty addr defers to the configuration file, then to DefaultAddr.

Types

type Module

type Module struct {
	platform.UnimplementedModule
	// contains filtered or unexported fields
}

Module routes requests to a per-domain module. Every virtual host gets its own router, so the modules keep mounting at their absolute paths and stay unaware of each other.

func NewModule

func NewModule(cfg *config.Config, opts ...Option) (*Module, error)

NewModule builds a virtual hosting module from a configuration. The configuration is expected to be valid, as config.Load returns it. Each vhost's content filesystem is opened here, so a path that does not exist is reported before the server starts.

func (*Module) Mount

func (m *Module) Mount(ctx context.Context, r platform.Router) error

Mount gives every virtual host its own router and installs the dispatcher as a catch all on the shared router. A vhost that fails to mount aborts startup: a site silently missing from a running server is worse than a server that refuses to start.

func (*Module) Name

func (m *Module) Name() string

Name returns the module name.

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start starts every virtual host's module.

func (*Module) Stop

func (m *Module) Stop(ctx context.Context) error

Stop stops every virtual host's module in reverse order. All modules are given a chance to stop; the first error is returned.

type Option

type Option func(*Module)

Option configures a Module.

func WithResolver

func WithResolver(resolver Resolver) Option

WithResolver replaces the filesystem resolver used to open vhost content.

type Resolver

type Resolver func(path string) (fs.FS, error)

Resolver opens the filesystem holding a virtual host's content. DirFS is the default; tests supply an in-memory filesystem instead.

Jump to

Keyboard shortcuts

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