exthttp

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 28 Imported by: 45 modules, 61 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 exthttp supports setup of HTTP servers to implement the *Kit contracts. To keep the resulting binary small the net/http server is used.

Index

Constants

View Source
const BindAddressLocalhost = "localhost"

BindAddressLocalhost binds to the IPv4 and IPv6 loopback addresses. Go would listen on only one address for the host name "localhost", so a client that resolves it to the other one could not connect.

Variables

This section is empty.

Functions

func BindAddress added in v1.13.0

func BindAddress() string

BindAddress returns the address that the extension and health HTTP servers bind to.

func BumpRevision added in v1.11.0

func BumpRevision()

BumpRevision advances the index revision. Kit SDKs call this from their Register*/Clear* functions whenever the set of registered describable elements changes.

func IsUnixSocketEnabled added in v1.8.0

func IsUnixSocketEnabled() bool

func Listen added in v1.6.0

func Listen(opts ListenOpts)

func ListenTCP added in v1.13.0

func ListenTCP(bindAddress string, port int) ([]net.Listener, error)

ListenTCP opens TCP listeners on the given port for the bind address. See STEADYBIT_EXTENSION_BIND_ADDRESS in the README for the accepted values. It fails if any of the listeners cannot be opened.

func ListenerAddresses added in v1.13.0

func ListenerAddresses(listeners []net.Listener) string

ListenerAddresses joins the listeners' addresses for log messages.

func LogRequestWithDefaultLogLevel added in v1.8.23

func LogRequestWithDefaultLogLevel(next Handler, defaultLevel zerolog.Level) http.Handler

func PanicRecovery

func PanicRecovery(next http.Handler) http.Handler

func RegisterHttpHandler

func RegisterHttpHandler(path string, handler Handler)

RegisterHttpHandler registers a handler for the given path. Also adds panic recovery, gzip compression and request logging around the handler.

func RegisterHttpHandlerWithLogLevel added in v1.8.23

func RegisterHttpHandlerWithLogLevel(path string, handler Handler, defaultLevel zerolog.Level)

RegisterHttpHandlerWithLogLevel registers a handler for the given path. Also adds panic recovery, gzip compression and request logging with a given log level around the handler.

func RegisterRevisionedHandler added in v1.11.0

func RegisterRevisionedHandler[T any](path string, getter func() T)

RegisterRevisionedHandler registers a handler that serves the getter's result at path, tagging the response with the current Revision() as its ETag so it supports conditional GET (a matching If-None-Match yields 304). Use this instead of hand-rolling IfNoneMatchHandler with a process-start timestamp, e.g. for the combined extension index.

func RequestTimeoutHeaderAware added in v1.7.4

func RequestTimeoutHeaderAware(next http.Handler) http.HandlerFunc

func Revision added in v1.11.0

func Revision() string

Revision returns the current index revision string. It changes on process start and whenever any kit registers/unregisters a describable element, so it is a safe ETag for the combined index.

func ServeListeners added in v1.13.0

func ServeListeners(listeners []net.Listener, serve func(net.Listener) error) error

ServeListeners runs serve for every listener and returns the first error. With http.Server, closing or shutting down the server ends all of them.

func SetDefaultBindAddress added in v1.13.0

func SetDefaultBindAddress(bindAddress string)

SetDefaultBindAddress sets the address that the extension and health HTTP servers bind to, unless overridden through the environment variable STEADYBIT_EXTENSION_BIND_ADDRESS. Empty (the default) binds to all interfaces. Call it before exthealth.StartProbes and Listen.

func SetTracingEnabled added in v1.12.0

func SetTracingEnabled(enabled bool)

SetTracingEnabled turns OpenTelemetry instrumentation on for handlers registered through RegisterHttpHandler. extotel.InitOpenTelemetry calls this once it has installed a real TracerProvider; an extension that configures the SDK itself, without extotel, has to call it too or its handlers will not be traced.

func StopListen added in v1.8.15

func StopListen()

func WaitForServe added in v1.8.15

func WaitForServe()

func WriteBody

func WriteBody(w http.ResponseWriter, response any)

WriteBody writes the given value as the HTTP response body as JSON with status code 200.

func WriteError

func WriteError(w http.ResponseWriter, err extension_kit.ExtensionError)

WriteError writes the error as the HTTP response body with status code 500.

Types

type CertReloader added in v1.8.3

type CertReloader struct {
	CertFile string
	KeyFile  string
	// contains filtered or unexported fields
}

func NewCertReloader added in v1.8.3

func NewCertReloader(certFile, keyFile string) *CertReloader

func (*CertReloader) GetCertificate added in v1.8.3

func (cr *CertReloader) GetCertificate(_ *tls.ClientHelloInfo) (*tls.Certificate, error)

type Handler added in v1.8.10

type Handler func(w http.ResponseWriter, r *http.Request, body []byte)

func GetterAsHandler

func GetterAsHandler[T any](handler func() T) Handler

GetterAsHandler turns a getter function into a handler function. Typically used in combination with the RegisterHttpHandler function.

func IfNoneMatchHandler added in v1.8.10

func IfNoneMatchHandler(etagFn func() string, delegate Handler) Handler

type ListenOpts added in v1.6.0

type ListenOpts struct {
	// Port Default port to bind to. Can be overridden through the environment variable STEADYBIT_EXTENSION_PORT.
	Port int
}

type ListenSpecification added in v1.6.0

type ListenSpecification struct {
	Port          int      `json:"port" split_words:"true" required:"false"`
	BindAddress   string   `json:"bindAddress" split_words:"true" required:"false"`
	UnixSocket    string   `json:"unixSocket" split_words:"true" required:"false"`
	TlsServerCert string   `json:"tlsServerCert" split_words:"true" required:"false"`
	TlsServerKey  string   `json:"tlsServerKey" split_words:"true" required:"false"`
	TlsClientCas  []string `json:"tlsClientCas" split_words:"true" required:"false"`
	EnablePprof   bool     `json:"enablePprof" split_words:"true" required:"false"`
}

Jump to

Keyboard shortcuts

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