-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.go
More file actions
41 lines (41 loc) · 1.88 KB
/
Copy pathdocs.go
File metadata and controls
41 lines (41 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Package apiweaver bundles composable HTTP helpers for building
// well-instrumented Go services. The module stays intentionally small and
// encourages teams to pull in only the packages they need, keeping binaries
// lean and dependencies predictable.
//
// The responder package centralises JSON rendering, structured errors, and
// trace-friendly metadata. The info package layers on status, version, and
// documentation endpoints along with an HTML viewer for your OpenAPI document.
// Probe helpers make it trivial to wire health checks for databases or bespoke
// functions into readiness/liveness routes, while jsonutil provides thin sonic
// wrappers for high-throughput encoding and decoding.
//
// # Packages
//
// - responder: consistent JSON success/error envelopes and structured logging
// hooks via functional options.
// - info: batteries-included health, version, and docs endpoints (including an
// embedded OpenAPI viewer and static assets).
// - probe: adapters that turn database ping functions or arbitrary closures
// into HTTP-friendly readiness checks.
// - jsonutil: tiny helpers around sonic for performance-sensitive encoding
// tasks.
//
// # Quick Start
//
// resp := responder.NewResponder(responder.WithLogger(logger))
// infoHandler := info.NewInfoHandler(
// info.WithInfoResponder(resp),
// info.WithBaseURL("https://api.example.com"),
// info.WithReadinessChecks(probe.NewMongoPingProbe(mongoClient, nil)),
// )
//
// mux := http.NewServeMux()
// mux.HandleFunc("/status", infoHandler.GetStatus)
// mux.HandleFunc("/version", infoHandler.GetVersion)
// mux.HandleFunc("/docs", infoHandler.GetOpenAPIHTML)
//
// Sharing the responder keeps JSON payloads, error envelopes, and trace IDs
// consistent. Additional options expose Swagger JSON, tweak the HTML template,
// or register extra readiness probes for bespoke dependencies.
package apiweaver