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 ¶
- func GetterAsHandler[T any](handler func() T) func(w http.ResponseWriter, r *http.Request, body []byte)
- func Listen(opts ListenOpts)
- func LogRequest(next func(w http.ResponseWriter, r *http.Request, body []byte)) http.HandlerFunc
- func LogRequestWithLevel(next func(w http.ResponseWriter, r *http.Request, body []byte), ...) http.HandlerFunc
- func LogRequestWithLevelFunc(next func(w http.ResponseWriter, r *http.Request, body []byte), ...) http.HandlerFunc
- func PanicRecovery(next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc
- func RegisterHttpHandler(path string, handler func(w http.ResponseWriter, r *http.Request, body []byte))
- func RequestTimeoutHeaderAware(next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc
- func WriteBody(w http.ResponseWriter, response any)
- func WriteError(w http.ResponseWriter, err extension_kit.ExtensionError)
- type ListenOpts
- type ListenSpecification
- type LoggingHttpResponseWriter
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 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 (w *LoggingHttpResponseWriter) Header() http.Header
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)
Click to show internal directories.
Click to hide internal directories.