exthttp

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: MIT Imports: 8 Imported by: 60

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 LogRequest

func LogRequest(next func(w http.ResponseWriter, r *http.Request, body []byte)) 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 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 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