api

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 59 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 determine 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 so the health check knows when to flag it as degraded (>2x interval).

Types

type Server

type Server struct {

	// Exported for main.go to wire the billing scheduler + 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 wires it via SetSettledChecker): action-required emails
	// whose invoice settled while queued are skipped, not delivered.
	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 wires its Cleanup into
	// the leader's cleanup steps.
	LoginThrottle *user.LoginThrottle

	// TestClockSvc lets main.go wire the async catchup queue + worker
	// (per ADR-015 — Stripe-style async test-clock advance) and run
	// boot recovery for any clocks left in 'advancing' from a prior
	// process. Construction is here in router.go, lifecycle is in
	// main.go alongside the rest of the background workers.
	TestClockSvc *testclock.Service
	// contains filtered or unexported fields
}

func NewServer

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

func (*Server) ServeHTTP

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

type ServerOption

type ServerOption func(*serverOptions)

ServerOption sets a boot-time value NewServer threads into the services it builds. cmd/hardcount passes the ones 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, config.Config.Env: 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.

Directories

Path Synopsis
Package generated provides primitives to interact with the openapi HTTP API.
Package generated provides primitives to interact with the openapi HTTP API.
Package middleware provides HTTP middleware for the Hardcount API server.
Package middleware provides HTTP middleware for the Hardcount API server.
Package timefilter is the shared parser for ?from / ?to (and named variants like ?date_from / ?date_to) query parameters across operator-facing list and export endpoints.
Package timefilter is the shared parser for ?from / ?to (and named variants like ?date_from / ?date_to) query parameters across operator-facing list and export endpoints.

Jump to

Keyboard shortcuts

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