Documentation
¶
Overview ¶
Package gosupport turns server-side errors in a Go app into Support tickets that carry the real server detail — no error tracker (Sentry etc.) required.
It is report-gated: on a 5xx the middleware BUFFERS the error detail locally (short TTL), keyed by a correlation id it stamps on the response. The detail is pushed to Support only when a user reports it (via the Flush handler you mount), so Support never stores errors nobody reported and the detail stays server-side until then.
r := gosupport.New(gosupport.Config{
IngestURL: "https://support-api.deftstar.dev/api/ingest/errors",
SecretKey: os.Getenv("SUPPORT_SECRET_KEY"),
})
mux.Handle("/support/errors/flush", authOnly(http.HandlerFunc(r.Flush))) // protect it
http.ListenAndServe(":8080", r.Middleware(mux))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
IngestURL string // Support ingest endpoint, e.g. https://support-api.deftstar.dev/api/ingest/errors
SecretKey string // project secret key (sk_...)
Source string // error source label; defaults to "local"
HeaderName string // correlation-id response header; defaults to "X-Request-Id"
TTL time.Duration // how long to buffer an error awaiting a report; defaults to 30m
Client *http.Client // HTTP client for pushes; defaults to a 5s-timeout client
NewID func() string // correlation-id generator; defaults to a random hex id
// Store buffers errors awaiting a report. Defaults to an in-process TTL store —
// fine for a single instance; provide a shared (e.g. Redis-backed) store if you
// run several, so the flush hits wherever the error was buffered.
Store Store
// Sample decides whether a completed request's status should be buffered.
// Defaults to "status >= 500".
Sample func(r *http.Request, status int) bool
OnError func(error) // observe push failures (best-effort)
}
Config configures a Reporter. Only IngestURL and SecretKey are required.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter buffers errors and, on report, pushes them to Support.
func (*Reporter) Flush ¶
func (r *Reporter) Flush(w http.ResponseWriter, req *http.Request)
Flush is an HTTP handler the app mounts (behind its own auth). It reads a correlation id (JSON body {"requestId":...} or the correlation header) and pushes that one buffered error to Support. Responds {"ok":true,"pushed":<bool>}.