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
- func BindAddress() string
- func BumpRevision()
- func IsUnixSocketEnabled() bool
- func Listen(opts ListenOpts)
- func ListenTCP(bindAddress string, port int) ([]net.Listener, error)
- func ListenerAddresses(listeners []net.Listener) string
- func LogRequestWithDefaultLogLevel(next Handler, defaultLevel zerolog.Level) http.Handler
- func PanicRecovery(next http.Handler) http.Handler
- func RegisterHttpHandler(path string, handler Handler)
- func RegisterHttpHandlerWithLogLevel(path string, handler Handler, defaultLevel zerolog.Level)
- func RegisterRevisionedHandler[T any](path string, getter func() T)
- func RequestTimeoutHeaderAware(next http.Handler) http.HandlerFunc
- func Revision() string
- func ServeListeners(listeners []net.Listener, serve func(net.Listener) error) error
- func SetDefaultBindAddress(bindAddress string)
- func SetTracingEnabled(enabled bool)
- func StopListen()
- func WaitForServe()
- func WriteBody(w http.ResponseWriter, response any)
- func WriteError(w http.ResponseWriter, err extension_kit.ExtensionError)
- type CertReloader
- type Handler
- type ListenOpts
- type ListenSpecification
Constants ¶
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
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
ListenerAddresses joins the listeners' addresses for log messages.
func LogRequestWithDefaultLogLevel ¶ added in v1.8.23
func RegisterHttpHandler ¶
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
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
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
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 ¶
GetterAsHandler turns a getter function into a handler function. Typically used in combination with the RegisterHttpHandler function.
func IfNoneMatchHandler ¶ added in v1.8.10
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"`
}