httpkit

package
v0.0.0-...-b02c7a7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PlainTextErrorHandler

func PlainTextErrorHandler(res http.ResponseWriter, err interface{})

PlainTextErrorHandler writes the error message as plain text to the HTTP response

func SimpleHTMLErrorHandler

func SimpleHTMLErrorHandler(res http.ResponseWriter, err interface{})

SimpleHTMLErrorHandler writes the error message as simple HTML to the HTTP response

Types

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, interface{})

An ErrorHandler takes a http.ResponseWriter and any error values and writes its error message to the ResponseWriter

type ExtendedResponse

type ExtendedResponse interface {
	Response
	io.Writer // Append data to the content

	SetHeader(string, string)
	DisableCaching()
	AllowCompression(*http.Request)
}

ExtendedResponse is a extension of the Response interface which adds some comfort functions and extended Features

func NewHTMLResponse

func NewHTMLResponse(status int) ExtendedResponse

NewHTMLResponse returns a new HTML response with the given status code

func NewJSONResponse

func NewJSONResponse(status int, data interface{}) ExtendedResponse

NewJSONResponse returns a new JSON response with the given status code and content

func NewPlainTextResponse

func NewPlainTextResponse(status int) ExtendedResponse

NewPlainTextResponse returns a new Plaintext response with the given status code

func NewRedirectResponse

func NewRedirectResponse(permanent bool, location string) ExtendedResponse

NewRedirectResponse returns a new Redirect Response

func NewResponse

func NewResponse(status int, contentType string, isText bool) ExtendedResponse

NewResponse returns a new Response with the given values

type HandlerBuilder

type HandlerBuilder struct {
	ErrorHandler ErrorHandler
}

The HandlerBuilder is used to set the default values for new instances of http.Handler

func (*HandlerBuilder) NewHandler

func (hb *HandlerBuilder) NewHandler(handleFunc func(*http.Request) (Response, error)) http.Handler

NewHandler returns a new generic HTTP handler

type Response

type Response interface {
	WriteResponse(http.ResponseWriter) error
}

Response represents a (before calling WriteResponse non-sent) HTTP response returned by the handler function.

func Handle404Plain

func Handle404Plain(req *http.Request) Response

Handle404Plain returns a plain text answer for the 404 error

func Handle404SimpleHTML

func Handle404SimpleHTML(req *http.Request) Response

Handle404SimpleHTML returns a simple HTML answer for the 404 error

Jump to

Keyboard shortcuts

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