Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EmptyData any
EmptyData is a placeholder that can be used inside the convenience function when no data should be responded.
Functions ¶
func Handle ¶
func Handle(f HandlerFunc) http.HandlerFunc
Handle translates a HandlerFunc into a http.HandleFunc.
func ListenGracefully ¶
func ListenGracefully(srv *http.Server, opts ...ShutdownOpt) error
ListenGracefully starts a http.Server and handles the shutdown process, when a syscall.SIGINT or syscall.SIGTERM are sent to the process.
Types ¶
type HandlerFunc ¶
HandlerFunc is the custom function that can be translated into a http.HandlerFunc.
type Response ¶
type Response struct { // The http status code that is used in response. StatusCode int // The headers that are used in the response. Headers map[string]string // The data that should be responded with. Data any }
Response holds all information that is needed to translate into a http response.
func BadRequest ¶
BadRequest is a convenience function to generate a Response with a http.StatusBadRequest.
func DecodeBody ¶
DecodeBody takes a http.Request and parses it into a struct v. It returns a bool, which indicates if the parsing was successful and a Response. In case of a decoding error, the Response indicates a http.StatusBadRequest.
func InternalServerError ¶
InternalServerError is a convenience function to generate a Response with a http.StatusInternalServerError.
type ShutdownConfig ¶
type ShutdownConfig struct { // the timeout for performing a graceful shutdown. Timeout time.Duration }
ShutdownConfig holds all variables needed in the shutdown process.
type ShutdownOpt ¶
type ShutdownOpt func(c *ShutdownConfig)
ShutdownOpt is a modifier function. They can be used to modify a ShutdownConfig.
func SetTimeout ¶
func SetTimeout(t time.Duration) ShutdownOpt
SetTimeout sets the timeout for performing a graceful shutdown.