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. Memory mode (no wal_path) 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 {
// WALLevel is the durability switch: 0 = memory only, 1 = background fsync
// (~1s window), 2 = fsync every write (slowest, safest). Above 0, WALPath
// is required.
WALLevel int `json:"wal_level,omitempty"`
// WALPath is the directory holding the write-ahead log segments. Required
// when wal_level > 0.
WALPath string `json:"wal_path,omitempty"`
// WALRotateMillis is how often the active segment is sealed, in ms. 0 = 5s.
WALRotateMillis int `json:"wal_rotate_ms,omitempty"`
// SQLitePath enables the on-disk SQLite mirror at this path (system of record
// + recovery source). Empty = no mirror. Requires wal_level > 0.
SQLitePath string `json:"sqlite_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"`
// 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_level 1
wal_path /var/lib/hazedb/wal
wal_rotation 5s
sqlite_path /var/lib/hazedb/hazedb.db
init_sql /etc/hazedb/schema.sql
registry_name default
}