Documentation
¶
Overview ¶
Package httpserver builds the Hertz server of the HTTP API: the middleware every request passes (tracing, request logging, CORS), the routes of package routes, and the Telegram webhook and payment notify handlers that their modules register.
Index ¶
Constants ¶
const ( // TrustNoProxy is the TrustedProxies entry that believes no forwarding // header: every client is the connection's peer. It is for a server its // clients reach directly, and it cannot be combined with other entries. TrustNoProxy = "none" // TrustPrivateNetworks is the entry that stands for the default networks // (appconfig.DefaultTrustedProxies) inside a longer list, so a public // proxy can be added without spelling the private ranges out. TrustPrivateNetworks = "private" )
const ( HealthzPath = "/healthz" ReadyzPath = "/readyz" )
Health endpoint paths, for the orchestrator's probes and the healthcheck command.
const ( DefaultProbeTTL = 5 * time.Second DefaultProbeTimeout = 2 * time.Second )
DefaultProbeTTL and DefaultProbeTimeout are the probe cache lifetime and the bound on one round of pings when HealthDependencies names none.
Variables ¶
This section is empty.
Functions ¶
func ParseTrustedProxies ¶ added in v1.21.0
ParseTrustedProxies parses the configured reverse proxies, each an IP address or a CIDR, into the networks whose X-Forwarded-For and X-Real-IP headers are believed. An empty configuration means the default networks, the entry "private" stands for them and ["none"] trusts nothing. It reports every entry that is none of these, so a typo does not silently widen or narrow the trust.
func RegisterHealthHandlers ¶ added in v1.21.0
func RegisterHealthHandlers(engine *server.Hertz, deps HealthDependencies)
RegisterHealthHandlers adds the liveness and readiness endpoints to engine. They carry no authentication and reveal nothing but a status and, when not ready, the name of the dependency that does not answer.
Types ¶
type Dependencies ¶
type Dependencies struct {
Routes routes.Dependencies
Notification notification.Service
TelegramBotToken func() string
RequestMetadata requestmeta.Enricher
// TrustedProxies lists the reverse proxies (IP addresses or CIDRs) whose
// X-Forwarded-For and X-Real-IP headers name the client. Empty believes
// no header: the client address is the connection's remote address.
TrustedProxies []string
// AllowedOrigins lists the browser origins CORS admits, as
// scheme://host[:port]. Empty reflects the request's Origin.
AllowedOrigins []string
// HTTP bounds the listener; a zero field leaves Hertz's default.
HTTP config.HTTPConfig
}
type HealthDependencies ¶ added in v1.21.0
type HealthDependencies struct {
Bootstrapped Readiness
Probes []Probe
// ProbeTTL is how long a probe result is reused, so readiness checks
// cannot hammer the database and Redis; zero means DefaultProbeTTL.
ProbeTTL time.Duration
// ProbeTimeout bounds one round of pings; zero means
// DefaultProbeTimeout.
ProbeTimeout time.Duration
}
HealthDependencies is what the health endpoints report on.
type Probe ¶ added in v1.21.0
Probe pings one dependency the server cannot serve without, such as the database or Redis. Name is what the readiness response reports when the ping fails; the error itself is only logged, so no address reaches a client.
type Readiness ¶ added in v1.21.0
type Readiness interface {
Done() <-chan struct{}
Err() error
}
Readiness is the runtime bootstrap's signal: Done closes once the runtime settings are loaded or the bootstrap failed, and Err reports the failure. The composition root's lifecycle.Readiness provides it.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Shutdown ¶
Shutdown stops accepting connections and waits for the open requests until ctx ends; Start returns nil afterwards.