exthttp

package
v1.7.15 Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: MIT Imports: 18 Imported by: 43

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

This section is empty.

Variables

This section is empty.

Functions

func GetterAsHandler

func GetterAsHandler[T any](handler func() T) func(w http.ResponseWriter, r *http.Request, body []byte)

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

func Listen added in v1.6.0

func Listen(opts ListenOpts)

func LogRequest

func LogRequest(next func(w http.ResponseWriter, r *http.Request, body []byte)) http.HandlerFunc

func LogRequestWithLevel added in v1.7.7

func LogRequestWithLevel(next func(w http.ResponseWriter, r *http.Request, body []byte), level zerolog.Level) http.HandlerFunc

func LogRequestWithLevelFunc added in v1.7.12

func LogRequestWithLevelFunc(next func(w http.ResponseWriter, r *http.Request, body []byte), level func(r *http.Request) zerolog.Level) http.HandlerFunc

func PanicRecovery

func PanicRecovery(next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc

func RegisterHttpHandler

func RegisterHttpHandler(path string, handler func(w http.ResponseWriter, r *http.Request, body []byte))

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

func RequestTimeoutHeaderAware added in v1.7.4

func RequestTimeoutHeaderAware(next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc

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 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"`

	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"`
}

type LoggingHttpResponseWriter added in v1.3.0

type LoggingHttpResponseWriter struct {
	// contains filtered or unexported fields
}

func (*LoggingHttpResponseWriter) Header added in v1.3.0

func (*LoggingHttpResponseWriter) Write added in v1.3.0

func (w *LoggingHttpResponseWriter) Write(bytes []byte) (int, error)

func (*LoggingHttpResponseWriter) WriteHeader added in v1.3.0

func (w *LoggingHttpResponseWriter) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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