api

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 61 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func SetSchedulerInterval(d time.Duration)

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.

func NewServer

func NewServer(db *postgres.DB, clk clock.Clock, rdb *redis.Client, opts ...ServerOption) *Server

NewServer builds every store, service and handler, wires them together and mounts the routes. A nil clk means the real clock. It panics when a required collaborator or audit emitter is not wired, or when the built-in recipes fail to load, so a broken build or wiring stops boot.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the request through the router.

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL