Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPMiddleware ¶
HTTPMiddleware adds a doppelganger factory for the body to the request. At the same time it replaces the original body with a doppelganger reader. You can specify a size limit for the reader (0 disables the limit) The factory can be fetched by using HTTPBodyFactory()
func IsNilReaderError ¶
IsNilReaderError returns true if the specified error is a NilReaderError
Types ¶
type DoppelgangerFactory ¶
type DoppelgangerFactory interface { NewDoppelganger() io.ReadCloser RemoveDoppelganger(r io.ReadCloser) error Close() error }
DoppelgangerFactory is a reader that mimics the behaviour of an other reader it can be used to read readers multiple times
Example (HttpErrorHandler) ¶
handler := http.NewServeMux() handler.HandleFunc("/", func(w http.ResponseWriter, request *http.Request) { _, _ = ioutil.ReadAll(request.Body) panic("some random error") }) http.ListenAndServe(":8000", errorHandler{handler})
Output:
func GetFactory ¶
func GetFactory(reader io.Reader) DoppelgangerFactory
GetFactory returns the DoppelgangerFactory if the reader is a Doppelganger
func HTTPBodyFactory ¶
func HTTPBodyFactory(r *http.Request) DoppelgangerFactory
HTTPBodyFactory returns a http body factory for a request. Notice that you have to use the HTTPMiddleware function.
func NewFactory ¶
func NewFactory(readerToMimic io.Reader) DoppelgangerFactory
NewFactory creates a new DoppelgangerFactory with the original reader specified if the reader is already a Doppelganger it will return the original factory
type NilReaderError ¶
type NilReaderError struct{}
NilReaderError will be reported if the provided reader is nil