uiversion

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 14 Imported by: 0

README

caddy-ui-version

Caddy HTTP handler that selects a UI document-root name from a SQLite database keyed by request host, and exposes it as {http.vars.ui_version}.

Caddyfile

{
	order ui_version before root
}

:80 {
	ui_version {
		sqlite file:/ui-versions.sqlite?immutable=1&mode=ro&nolock=1
		default original
	}

	root * /{http.vars.ui_version}
	file_server
}

SQLite schema

CREATE TABLE domains (
  name TEXT PRIMARY KEY NOT NULL,
  ui_version TEXT NOT NULL
);

name is the bare hostname (lowercase, no port). Missing hosts use default (typically original).

The sample DB maps dagplannen.nlmodern.

Update strategy

Same model as CoreDNS nameshift_context:

  • Open a stable pool against an immutable read-only URI
  • Connections recycle every 5 minutes (SetConnMaxLifetime)
  • Publishers replace /ui-versions.sqlite atomically (mv)
  • In-memory host cache is cleared every 15 minutes

Build

xcaddy build --with github.com/randock/caddy-ui-version@v0.0.2

Sample database

go run ./cmd/mksampledb -o ui-versions.sqlite

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UIVersion

type UIVersion struct {
	// SQLite is the path / URI to the domains database. Prefer the CoreDNS
	// style URI, e.g. file:/ui-versions.sqlite?immutable=1&mode=ro&nolock=1
	SQLite string `json:"sqlite,omitempty"`

	// Default is used when the host is missing from the database.
	Default string `json:"default,omitempty"`
	// contains filtered or unexported fields
}

UIVersion looks up the Host header in a SQLite database and sets {http.vars.ui_version} so later directives (e.g. root) can select a site tree.

Open the DB the same way as CoreDNS nameshift_context: a stable pool against an immutable read-only URI. Publishers replace the file atomically (mv); pool connections recycle every 5m so the new inode becomes visible. An in-memory host cache is cleared every 15m so stale mappings do not linger longer than that after an update.

func (UIVersion) CaddyModule

func (UIVersion) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*UIVersion) Cleanup

func (m *UIVersion) Cleanup() error

Cleanup closes the database and stops the cache clearer.

func (*UIVersion) Provision

func (m *UIVersion) Provision(ctx caddy.Context) error

Provision sets up the module.

func (UIVersion) ServeHTTP

func (m UIVersion) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*UIVersion) UnmarshalCaddyfile

func (m *UIVersion) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

ui_version {
    sqlite file:/ui-versions.sqlite?immutable=1&mode=ro&nolock=1
    default original
}

func (*UIVersion) Validate

func (m *UIVersion) Validate() error

Validate implements caddy.Validator.

Directories

Path Synopsis
cmd
mksampledb command

Jump to

Keyboard shortcuts

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