Documentation
¶
Overview ¶
Package labkit holds the small pieces every PackLab reference app shares: JSON helpers, fix flags, bearer tokens, a minimal OpenAPI document, a work counter used to show where the planted bottlenecks spend their time, and the App shape of the apps that also listen on another protocol.
Index ¶
- func Bearer(r *http.Request) string
- func Decode(w http.ResponseWriter, r *http.Request, v any) bool
- func Dialable(addr net.Addr) string
- func Error(w http.ResponseWriter, status int, code, msg string)
- func JSON(w http.ResponseWriter, status int, v any)
- func OpenAPI(title, description string, routes []Route) http.HandlerFunc
- func Token(prefix string) string
- type App
- type Config
- type Counter
- type Fixes
- type Gauge
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dialable ¶
Dialable returns a listener's address as a client on this machine can dial it: an unspecified host (":8111", "[::]:8111") becomes localhost.
func Error ¶
func Error(w http.ResponseWriter, status int, code, msg string)
Error writes {"error": {"code": code, "message": msg}}.
Types ¶
type App ¶
type App struct {
// Handler serves the HTTP side: the API, /healthz and /openapi.json.
Handler http.Handler
// Env holds what the pack's scenarios need besides TARGET_URL to
// reach the other listeners, such as MQTT_BROKER=tcp://127.0.0.1:8111.
Env map[string]string
// Close stops the other listeners.
Close func()
}
App is a reference app that serves more than HTTP: a broker, a cache or a UDP server next to its HTTP API.
type Config ¶
type Config struct {
// Fixes switches planted bottlenecks off.
Fixes Fixes
// Fast shortens deliberate waits (token pacing, admission ticks) so
// tests run quickly. Bottlenecks stay in place.
Fast bool
// Listen is the address of an app's second listener (its MQTT broker,
// Kafka cluster, Redis server or UDP game server), for the apps that
// have one. Tests use "127.0.0.1:0".
Listen string
// Postgres is the PostgreSQL connection string DBLab seeds its tables
// into.
Postgres string
}
Config is what every reference app is built from.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter counts units of work so tests and /debug/work can show what a bottleneck costs.
type Fixes ¶
Fixes says which planted bottlenecks are switched off. The zero value keeps every bottleneck in place.
func ParseFixes ¶
ParseFixes reads a comma-separated list such as "lock,index" or "all".