http

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package http is GTB's framework-integration layer over the extracted HTTP transport modules.

The hardened HTTP server now lives in gitlab.com/phpboyscout/go/transport/http and the HTTP client in gitlab.com/phpboyscout/go/httpclient; this package binds them to the GTB config store. It provides the config-driven server adapters — ServerSettingsFromConfig, ObserveServerSettingsFromConfig, NewServerFromReader, StartFromReader, RegisterFromReader, plus RateLimitConfigFromConfig / CircuitBreakerConfigFromConfig — which read a service's config and call the transport constructors. The GTB config-selection options WithConfigPrefix and WithPort steer that resolution. The config adapters name the go/transit HTTP middleware types (RateLimitConfig, CircuitBreakerConfig) directly.

The secure client factory and HTTP middleware are no longer re-exported here: code that wants the pure server or client API imports gitlab.com/phpboyscout/go/transport/http, gitlab.com/phpboyscout/go/httpclient, or gitlab.com/phpboyscout/go/transit/http directly.

Index

Constants

View Source
const DefaultConfigPrefix = "server.http"

DefaultConfigPrefix is the config block an HTTP server reads its port, TLS and max_header_bytes from unless overridden with WithConfigPrefix.

Variables

This section is empty.

Functions

func CircuitBreakerConfigFromConfig added in v0.23.0

func CircuitBreakerConfigFromConfig(cfg config.Reader, prefix string) transithttp.CircuitBreakerConfig

CircuitBreakerConfigFromConfig builds a transithttp.CircuitBreakerConfig from the config layer under "<prefix>.circuitbreaker.*" (prefix defaults to "server.http").

Unset keys keep their transithttp.DefaultCircuitBreakerConfig values. The code-only fields (IsFailure, OnStateChange) are never read from config.

func NewServerFromReader added in v0.32.0

func NewServerFromReader(ctx context.Context, cfg config.Reader, handler http.Handler, opts ...any) (*http.Server, error)

NewServerFromReader returns a new preconfigured http.Server. With no options it reads from the default "server.http" config prefix; pass a GTB WithConfigPrefix/WithPort to select the config block, and transport ServerOption values (timeouts, TLS) to configure the server.

func ObserveServerSettingsFromConfig added in v0.30.0

ObserveServerSettingsFromConfig binds HTTP server settings to cfg and keeps a typed snapshot rehydrated after successful config reloads.

func RateLimitConfigFromConfig added in v0.23.0

func RateLimitConfigFromConfig(cfg config.Reader, prefix string) transithttp.RateLimitConfig

RateLimitConfigFromConfig builds a transithttp.RateLimitConfig from the config layer under "<prefix>.ratelimit.*" (prefix defaults to "server.http"), so operators tune the limiter via config like they tune the port or TLS.

Unset keys keep their transithttp.DefaultRateLimitConfig values. The code-only fields (KeyFunc, OnLimited) are never read from config; wiring stays explicit.

func RegisterFromReader added in v0.32.0

func RegisterFromReader(ctx context.Context, id string, controller controls.Controllable, cfg config.Reader, log logger.Logger, handler http.Handler, opts ...any) (*http.Server, error)

RegisterFromReader creates a new HTTP server and registers it with the controller under the given id. The opts variadic accepts GTB config-selection options (WithConfigPrefix, WithPort) plus transport ServerOption and RegisterOption values (timeouts, middleware, body limit).

func ServerSettingsFromConfig added in v0.30.0

func ServerSettingsFromConfig(cfg config.Reader, prefix string) transporthttp.ServerSettings

ServerSettingsFromConfig resolves HTTP server settings from GTB config. It preserves the existing fallback from <prefix>.port to server.port and keeps max_header_bytes scoped to the selected prefix.

func StartFromReader added in v0.32.0

func StartFromReader(cfg config.Reader, log logger.Logger, srv *http.Server, opts ...any) controls.StartFunc

StartFromReader returns a curried function suitable for use with the controls package. With no options it reads TLS from the default "server.http" config prefix; pass WithConfigPrefix to match a server on a custom prefix.

Types

type ServerOption added in v0.9.0

type ServerOption func(*serverConfig)

ServerOption selects which GTB config block (and, optionally, an explicit port) the *FromReader adapters read. It is distinct from the transport's own gitlab.com/phpboyscout/go/transport/http.ServerOption (timeouts, TLS, max-header-bytes); the adapters accept both — GTB options steer config resolution, transport options are forwarded to the constructor.

func WithConfigPrefix added in v0.6.0

func WithConfigPrefix(prefix string) ServerOption

WithConfigPrefix sets the config block the server reads from (default "server.http"). Use it to run a second HTTP server on its own block, e.g. "server.admin".

func WithPort added in v0.9.0

func WithPort(port int) ServerOption

WithPort sets the listen port explicitly, bypassing config lookup entirely. It has the highest precedence: it overrides both <prefix>.port and the server.port shared fallback.

Jump to

Keyboard shortcuts

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