Documentation
¶
Overview ¶
Package api provides the HTTP server and route wiring for Hardcount. It creates domain stores, services, and handlers, then mounts them on a chi router with auth, rate limiting, and metrics middleware.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecordSchedulerRun ¶
func RecordSchedulerRun()
RecordSchedulerRun is called by the billing scheduler after each cycle, so the health check can tell whether the scheduler is alive.
func SetDraining ¶
func SetDraining()
SetDraining announces shutdown: readiness answers 503 from now on.
func SetSchedulerInterval ¶
SetSchedulerInterval stores the configured scheduler interval. The health check flags the scheduler as degraded when more than two intervals pass after its last run.
Types ¶
type Server ¶
type Server struct {
BillingEngine *billing.Engine
DunningSvc *dunning.Service
SettingsStore *tenant.SettingsStore
WebhookOutSvc *webhook.Service
OutboxStore *webhook.OutboxStore
EmailOutboxStore *email.OutboxStore
EmailSender *email.Sender
// EmailSettledChecker lets the email dispatcher skip an action-required
// email whose invoice was settled while it was queued.
EmailSettledChecker email.InvoiceSettledChecker
CreditSvc *credit.Service
InvoiceSvc *invoice.Service
CreditNoteSvc *creditnote.Service
SubscriptionSvc *subscription.Service
TokenSvc *payment.TokenService
PaymentReconciler *payment.Reconciler
LoginThrottle *user.LoginThrottle
// TestClockSvc runs the test-clock catch-up off the request: what fell due
// in the time an advancing clock skipped (ADR-140).
TestClockSvc *testclock.Service
// RestoreCatchUp applies Stripe's events to a restored database through
// the webhook handlers (ADR-135); only `hardcount restore catch-up` runs
// it.
RestoreCatchUp *payment.CatchUp
// contains filtered or unexported fields
}
Server is the HTTP API. Its exported fields hold the services and stores that cmd/hardcount wires into the background workers.
type ServerOption ¶
type ServerOption func(*serverOptions)
ServerOption sets a boot-time value that cmd/hardcount reads from config. Tests set only what they exercise.
func WithAppEnv ¶
func WithAppEnv(env string) ServerOption
WithAppEnv sets the environment, APP_ENV as config.Load normalised it. Without it the server runs as "local".
func WithInvoiceGrace ¶
func WithInvoiceGrace(d time.Duration) ServerOption
WithInvoiceGrace sets INVOICE_GRACE_PERIOD (ADR-120). The billing runs' due scans and the backlog gauges take the same value, so they agree on when a period is due.
func WithRateLimits ¶
func WithRateLimits(rl config.RateLimits) ServerOption
WithRateLimits sets the HARDCOUNT_RATE_LIMIT_* limits config.Load parsed. Without it NewServer uses config.DefaultRateLimits.
func WithStripeKeys ¶ added in v0.10.0
func WithStripeKeys(keys map[tenantstripe.Account]string) ServerOption
WithStripeKeys replaces stored Stripe keys for the life of this Server, without saving them. Only `hardcount restore catch-up --stripe-key` uses it.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package middleware holds the HTTP middleware of the API server.
|
Package middleware holds the HTTP middleware of the API server. |
|
Package respond writes the API's JSON responses: success bodies, list pages and the error envelope.
|
Package respond writes the API's JSON responses: success bodies, list pages and the error envelope. |
|
Package timefilter parses the ?from and ?to query parameters, and named variants such as ?date_from and ?date_to, for the operator-facing list and export endpoints.
|
Package timefilter parses the ?from and ?to query parameters, and named variants such as ?date_from and ?date_to, for the operator-facing list and export endpoints. |