Documentation
¶
Overview ¶
Package caddymodule exposes hazedb as a Caddy HTTP handler.
The core hazedb package stays Caddy-free; this adapter owns the transport: it opens a *DB, serves GET /get (single-row read), GET /list (multi-row read), POST /query, POST /exec, and GET /meta (store-size overview) over an internal mux, and registers the *DB under a name in the core registry so an in-process consumer (the FrankenPHP/PHP extension) reaches the very same instance. Per the gateway boundary in the RFC, request-context cross-cutting concerns (auth, per-tenant routing, rate limits) belong here, never in core.
Schema: the module opens with an empty schema by default. hazedb supports runtime CREATE TABLE, so operators define tables via an init_sql file (run once at Provision) or by POSTing DDL to /exec.
WAL + reload caveat: with wal_path set, Caddy config reload runs the new Provision (which opens the same file) before the old Cleanup (which closes it) — two writers on one WAL file for that window. Since WAL is on by default, this applies to a default deployment; memory mode (wal off) reloads cleanly. For durable deployments, restart rather than graceful-reload when changing this handler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// WAL switches the write-ahead log on or off. "on" (the default; empty means
// the default) makes the store durable: a write is sealed to disk within ~0.5s,
// so a crash loses at most that window. "off" is memory-only — nothing persists
// across a restart.
WAL string `json:"wal,omitempty"`
// WALPath optionally overrides the directory holding the WAL segments. Empty
// uses the default <caddy-data-dir>/hazedb/wal. Ignored when wal is off.
WALPath string `json:"wal_path,omitempty"`
// CompanionPath optionally overrides where the SQLite companion file lives —
// always a real file on disk, present whether wal is on or off. It holds the
// _hz_events operational log (logging, health) in every mode, plus the data
// mirror and recovery base when wal is on. Empty defaults to
// <caddy-data-dir>/hazedb/hazedb.db, or <wal_path>/hazedb.db when a custom
// wal_path is set. An in-memory path (:memory:) is rejected — never in-memory.
CompanionPath string `json:"companion_path,omitempty"`
// InitSQL is an absolute path to a .sql file run once at Provision, before
// Caddy serves — typically CREATE TABLE + seed rows. Statements are split on
// ';'; do not put a semicolon inside a string literal in this file.
InitSQL string `json:"init_sql,omitempty"`
// RegistryName is the name the *DB is published under for in-process
// consumers. Empty = "default" (what the PHP extension looks up).
RegistryName string `json:"registry_name,omitempty"`
// MaxBodyBytes caps the POST body for /query and /exec, in bytes. 0 = the
// 4 MiB default. Bounds per-request memory against an oversized body — and
// since the SQL string and the positional-arg array both live in that body,
// it bounds their sizes too.
MaxBodyBytes int64 `json:"max_body_bytes,omitempty"`
// MaxBytes caps the store's total in-RAM size, in bytes. 0 = unlimited. An
// INSERT that would push the store past it is rejected with HTTP 507; the
// store never auto-evicts, so the client frees space with DELETE / DROP TABLE.
// Distinct from MaxBodyBytes (a per-request limit) — this bounds the whole
// dataset.
MaxBytes int64 `json:"max_bytes,omitempty"`
// contains filtered or unexported fields
}
Handler is the Caddy HTTP handler that embeds hazedb.
func (Handler) CaddyModule ¶
func (Handler) CaddyModule() caddy.ModuleInfo
CaddyModule registers the handler under http.handlers.* so it works as a `handle`/`hazedb` directive or a JSON handler entry.
func (*Handler) Cleanup ¶
Cleanup deregisters and closes the *DB. DeregisterDBIf is the CAS-safe form: during a config reload the new Provision has already overwritten the slot, so this won't clobber it; it only clears when the handler is fully removed.
func (*Handler) Provision ¶
Provision opens the *DB, runs init_sql, wires the routes, and registers the instance. Called once per module instance at Caddy start / config reload.
func (*Handler) ServeHTTP ¶
ServeHTTP dispatches to the hazedb mux; unmatched paths fall through to the next handler, so the module can be mounted under a prefix alongside others.
func (*Handler) UnmarshalCaddyfile ¶
UnmarshalCaddyfile parses the `hazedb` handler directive. Example:
hazedb {
wal on # on (default) | off (memory-only)
wal_path /var/lib/hazedb/wal # optional: override the WAL directory
companion_path /var/lib/hazedb/hazedb.db
init_sql /etc/hazedb/schema.sql
registry_name default
max_bytes 1073741824
}