Documentation ¶
Index ¶
- func Response(fn ResModifierFunc) func(http.Handler) http.Handler
- type Filter
- type ReqModifierFunc
- type RequestInterceptor
- type RequestModifier
- func (s *RequestModifier) Bytes(body []byte)
- func (s *RequestModifier) DecodeJSON(userStruct interface{}) error
- func (s *RequestModifier) DecodeXML(userStruct interface{}, charsetReader XMLCharDecoder) error
- func (s *RequestModifier) JSON(data interface{}) error
- func (s *RequestModifier) ReadBytes() ([]byte, error)
- func (s *RequestModifier) ReadString() (string, error)
- func (s *RequestModifier) Reader(body io.Reader) error
- func (s *RequestModifier) String(body string)
- func (s *RequestModifier) XML(data interface{}) error
- type ResModifierFunc
- type ResponseModifier
- func (s *ResponseModifier) Bytes(body []byte)
- func (s *ResponseModifier) DecodeJSON(userStruct interface{}) error
- func (s *ResponseModifier) DecodeXML(userStruct interface{}, charsetReader XMLCharDecoder) error
- func (s *ResponseModifier) JSON(data interface{}) error
- func (s *ResponseModifier) ReadBytes() ([]byte, error)
- func (s *ResponseModifier) ReadString() (string, error)
- func (s *ResponseModifier) Reader(body io.Reader) error
- func (s *ResponseModifier) Status(status int)
- func (s *ResponseModifier) String(body string)
- func (s *ResponseModifier) XML(data interface{}) error
- type WriterInterceptor
- type XMLCharDecoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ReqModifierFunc ¶
type ReqModifierFunc func(*RequestModifier)
ReqModifierFunc represent the function interface for request modifiers.
type RequestInterceptor ¶
type RequestInterceptor struct { Modifier ReqModifierFunc Filters []Filter }
RequestInterceptor interceps a given http.Request using a custom request modifier function.
func Request ¶
func Request(h ReqModifierFunc) *RequestInterceptor
Request intercepts an HTTP request and passes it to the given request modifier function.
func (*RequestInterceptor) Filter ¶
func (s *RequestInterceptor) Filter(f ...Filter)
Filter intercepts an HTTP requests if and only if the given filter returns true.
func (*RequestInterceptor) HandleHTTP ¶
func (s *RequestInterceptor) HandleHTTP(w http.ResponseWriter, r *http.Request, h http.Handler)
HandleHTTP handles the middleware call chain, intercepting the request data if possible. This methods implements the middleware layer compatible interface.
type RequestModifier ¶
type RequestModifier struct { // Header exposes the request http.Header type. Header http.Header // Request exposes the current http.Request to be modified. Request *http.Request }
RequestModifier implements a convenient abstraction to modify an http.Request, including methods to read, decode/encode and define JSON/XML/String/Binary bodies and modify HTTP headers.
func NewRequestModifier ¶
func NewRequestModifier(req *http.Request) *RequestModifier
NewRequestModifier creates a new request modifier that modifies the given http.Request.
func (*RequestModifier) Bytes ¶
func (s *RequestModifier) Bytes(body []byte)
Bytes sets the given bytes as http.Request body.
func (*RequestModifier) DecodeJSON ¶
func (s *RequestModifier) DecodeJSON(userStruct interface{}) error
DecodeJSON reads and parses the current http.Request body and tries to decode it as JSON.
func (*RequestModifier) DecodeXML ¶
func (s *RequestModifier) DecodeXML(userStruct interface{}, charsetReader XMLCharDecoder) error
DecodeXML reads and parses the current http.Request body and tries to decode it as XML.
func (*RequestModifier) JSON ¶
func (s *RequestModifier) JSON(data interface{}) error
JSON sets the given JSON serializable struct as http.Request body defining the proper content length header.
func (*RequestModifier) ReadBytes ¶
func (s *RequestModifier) ReadBytes() ([]byte, error)
ReadBytes reads the whole body of the current http.Request and returns it as bytes.
func (*RequestModifier) ReadString ¶
func (s *RequestModifier) ReadString() (string, error)
ReadString reads the whole body of the current http.Request and returns it as string.
func (*RequestModifier) Reader ¶
func (s *RequestModifier) Reader(body io.Reader) error
Reader sets the given io.Reader stream as http.Request body defining the proper content length header.
func (*RequestModifier) String ¶
func (s *RequestModifier) String(body string)
String sets the given string as http.Request body.
func (*RequestModifier) XML ¶
func (s *RequestModifier) XML(data interface{}) error
XML sets the given XML serializable struct as http.Request body defining the proper content length header.
type ResModifierFunc ¶
type ResModifierFunc func(*ResponseModifier)
ResModifierFunc defines the function interface for http.Response modifiers.
type ResponseModifier ¶
ResponseModifier implements a convenient abstraction to modify an http.Response, including methods to read, decode/encode and define JSON/XML/String/Binary bodies and modify HTTP headers.
func NewResponseModifier ¶
func NewResponseModifier(req *http.Request, res *http.Response) *ResponseModifier
NewResponseModifier creates a new response modifier that modifies the given http.Response.
func (*ResponseModifier) Bytes ¶
func (s *ResponseModifier) Bytes(body []byte)
Bytes sets the given bytes as http.Response body.
func (*ResponseModifier) DecodeJSON ¶
func (s *ResponseModifier) DecodeJSON(userStruct interface{}) error
DecodeJSON reads and parses the current http.Response body and tries to decode it as JSON.
func (*ResponseModifier) DecodeXML ¶
func (s *ResponseModifier) DecodeXML(userStruct interface{}, charsetReader XMLCharDecoder) error
DecodeXML reads and parses the current http.Response body and tries to decode it as XML.
func (*ResponseModifier) JSON ¶
func (s *ResponseModifier) JSON(data interface{}) error
JSON sets the given JSON serializable struct as http.Response body defining the proper content length header.
func (*ResponseModifier) ReadBytes ¶
func (s *ResponseModifier) ReadBytes() ([]byte, error)
ReadBytes reads the whole body of the current http.Response and returns it as bytes.
func (*ResponseModifier) ReadString ¶
func (s *ResponseModifier) ReadString() (string, error)
ReadString reads the whole body of the current http.Response and returns it as string.
func (*ResponseModifier) Reader ¶
func (s *ResponseModifier) Reader(body io.Reader) error
Reader sets the given io.Reader stream as http.Response body defining the proper content length header.
func (*ResponseModifier) Status ¶
func (s *ResponseModifier) Status(status int)
Status sets a new status code in the http.Response to be modified.
func (*ResponseModifier) String ¶
func (s *ResponseModifier) String(body string)
String sets the given string as http.Response body.
func (*ResponseModifier) XML ¶
func (s *ResponseModifier) XML(data interface{}) error
XML sets the given XML serializable struct as http.Response body defining the proper content length header.
type WriterInterceptor ¶
type WriterInterceptor struct {
// contains filtered or unexported fields
}
WriterInterceptor implements an http.ResponseWriter compatible interface that will intercept and buffer any method call until the body writes is completed, and then will call the http.Response modifier function to intercept and modify it accordingly before writting the final response fields.
func NewWriterInterceptor ¶
func NewWriterInterceptor(w http.ResponseWriter, req *http.Request, fn ResModifierFunc) *WriterInterceptor
NewWriterInterceptor creates a new http.ResponseWriter capable interface that will intercept the current response.
func (*WriterInterceptor) Close ¶
func (w *WriterInterceptor) Close()
Close closes the body readers and flags the interceptor as closed status.
func (*WriterInterceptor) DoWrite ¶
func (w *WriterInterceptor) DoWrite() (int, error)
DoWrite writes the final HTTP response header and body in the real http.ResponseWriter.
func (*WriterInterceptor) Header ¶
func (w *WriterInterceptor) Header() http.Header
Header returns the current response http.Header.
func (*WriterInterceptor) Write ¶
func (w *WriterInterceptor) Write(b []byte) (int, error)
Write intercepts and stores chunks of bytes as part of the response body.
func (*WriterInterceptor) WriteHeader ¶
func (w *WriterInterceptor) WriteHeader(status int)
WriteHeader intercepts the desired response status code.
type XMLCharDecoder ¶
XMLCharDecoder is a helper type that takes a stream of bytes (not encoded in UTF-8) and returns a reader that encodes the bytes into UTF-8. This is done because Go's XML library only supports XML encoded in UTF-8.