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 {
// Exported so main.go can wire the billing scheduler and dunning.
BillingEngine *billing.Engine
DunningSvc *dunning.Service
SettingsStore *tenant.SettingsStore
WebhookOutSvc *webhook.Service
OutboxStore *webhook.OutboxStore
EmailOutboxStore *email.OutboxStore
EmailSender *email.Sender
// EmailSettledChecker feeds the email dispatcher's staleness gate.
// cmd/hardcount passes it to the dispatcher with SetSettledChecker. The
// dispatcher skips 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 is the sign-in throttle. main.go adds its Cleanup to the
// leader's cleanup steps.
LoginThrottle *user.LoginThrottle
// TestClockSvc lets main.go wire the catch-up queue and worker, and run
// boot recovery for clocks that an earlier process left 'advancing'.
// Catch-up runs everything that fell due in the time a test clock
// skipped, such as trial ends, billing, tax retries, dunning and credit
// expiries. It runs off the request, as Stripe's test-clock advance does
// (ADR-015). The service is built here, and main.go runs it with the
// other background workers.
TestClockSvc *testclock.Service
// 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 NewServer passes to the services it builds. cmd/hardcount passes what config.Load read. Tests pass what they exercise, and otherwise run as an install with none of them set.
func WithAppEnv ¶
func WithAppEnv(env string) ServerOption
WithAppEnv sets the environment to config.Config.Env, which is APP_ENV as config.Load normalised it, so every consumer below compares the same string. Without it, NewServer runs as "local", as an unset APP_ENV does.
func WithInvoiceGrace ¶
func WithInvoiceGrace(d time.Duration) ServerOption
WithInvoiceGrace sets INVOICE_GRACE_PERIOD (ADR-120). One value feeds the two places that must agree on when a period is due: the billing runs' due scans and the billing backlog gauges. The credit-expiry sweep does not use it: it holds a grant until the close that draws on it has run (ADR-071 §2).
func WithRateLimits ¶
func WithRateLimits(rl config.RateLimits) ServerOption
WithRateLimits sets the HARDCOUNT_RATE_LIMIT_* limits config.Load parsed. Without it NewServer uses config.DefaultRateLimits.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package middleware provides HTTP middleware for the Hardcount API server.
|
Package middleware provides HTTP middleware for the Hardcount 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. |