Documentation ¶
Overview ¶
Package response provides wrapper around http.ResponseWriter used inside context object, also it provides some commonly-used response payloads.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Error{Error: "unauthorized"} // BadRequest error response is supposed to be sent to the client on bad request error. BadRequest = Error{Error: "bad request"} // InternalError error response is supposed to be sent to the client on internal error. InternalError = Error{Error: "internal error"} )Unauthorized =
var ( // Ok response is supposed to be sent to the client on success. Ok = Message{Message: "OK"} )
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
Error string `json:"error"`
}
Error structure provides the most basic error payload sent to the client.
type Message ¶
type Message struct {
Message string `json:"message"`
}
Message structure provides the most basic payload with message sent to the client.
type Writer ¶
type Writer struct { http.ResponseWriter // contains filtered or unexported fields }
Writer structure is a wrapper around http.ResponseWriter. It can be used to intercept and retrieve written http status. It is used inside context object and you won't probably use it yourself.
func (*Writer) HeaderWritten ¶
HeaderWritten method retrieves flag - is header already written or not.
func (*Writer) Reset ¶
func (w *Writer) Reset(responseWriter http.ResponseWriter)
Reset method prepares structure for the next request.
func (*Writer) Write ¶
Write method writes data into the response and calls WriteHeader method if header is not already written.
func (*Writer) WriteHeader ¶
WriteHeader method writes header into the response and intercepts status code.