Documentation ¶
Index ¶
- Constants
- Variables
- type Body
- type HTTPStatus
- type Response
- func NewError(e error) *Response
- func NewErrorWithStatus(e error, code HTTPStatus) *Response
- func NewHTML(template *template.Template, data interface{}) *Response
- func NewHTMLWithStatus(template *template.Template, data interface{}, code HTTPStatus) *Response
- func NewJSON(v interface{}) *Response
- func NewJSONWithStatus(v interface{}, code HTTPStatus) *Response
- func NewRedirect(url string) *Response
- func NewRedirectWithStatus(url string, status HTTPStatus) *Response
- func NewResponse(body Body) *Response
- func NewResponseWithStatus(body Body, status HTTPStatus) *Response
- func NewText(s interface{}) *Response
- func NewTextWithStatus(s interface{}, code HTTPStatus) *Response
Constants ¶
const (
ContentType string = "content-type"
)
Widely used headers
Variables ¶
var NoContent = &noContent{}
var UseEmptyIfSliceIsZero = true
UseEmptyIfSliceIsZero is a configuration variable about if the data is an empty slice ([]T{}), then render [] instead of null (Go's default JSON behavior)
var UseFormattedJSON = false
UseFormattedJSON is a configuration variable about if json object is formatted or not.
Functions ¶
This section is empty.
Types ¶
type HTTPStatus ¶
type HTTPStatus int
HTTPStatus is an enum for http status code
const ( HTTPStatusOK HTTPStatus = 200 + iota HTTPStatusCreated HTTPStatusAccepted HTTPStatusNonAuthoritativeInformation HTTPStatusNoContent HTTPStatusResetContent HTTPStatusPartialContent )
Available status code for 2xx
const ( HTTPStatusMovedParmanently HTTPStatus = 301 + iota HTTPStatusFound HTTPStatusSeeOther HTTPStatusNotModified HTTPStatusUseProxy )
Available status code for 3xx
const ( HTTPStatusBadRequest HTTPStatus = 400 + iota HTTPStatusPaymentRequired HTTPStatusForbidden HTTPStatusNotFound HTTPStatusMethodNotAllowed HTTPStatusNotAcceptable HTTPStatusProxyAuthenticationRequired HTTPStatusRequestTimeout HTTPStatusCoflict HTTPStatusGone HTTPStatusLengthRequired HTTPStatusPreconditionFailed HTTPStatusPayloadTooLarge HTTPStatusURITooLong HTTPStatusRangeNotSatisfiable HTTPStatusExpectationFailed )
Available status code for 4xx
const ( HTTPStatusInternalServerError HTTPStatus = 500 + iota HTTPStatusNotImplemented HTTPStatusBadGateway HTTPStatusGatewayTimeout )
Available status code for 5xx
func MustParseHTTPStatus ¶
func MustParseHTTPStatus(s string) HTTPStatus
func ParseHTTPStatus ¶
func ParseHTTPStatus(s string) (HTTPStatus, error)
func ParseHTTPStatusOr ¶
func ParseHTTPStatusOr(s string, or HTTPStatus) HTTPStatus
func (HTTPStatus) MarshalJSON ¶
func (i HTTPStatus) MarshalJSON() ([]byte, error)
func (HTTPStatus) String ¶
func (i HTTPStatus) String() string
func (*HTTPStatus) UnmarshalJSON ¶
func (i *HTTPStatus) UnmarshalJSON(b []byte) error
type Response ¶
Response represents http response.
func NewErrorWithStatus ¶
func NewErrorWithStatus(e error, code HTTPStatus) *Response
NewErrorWithStatus returns an error response with the given status code
func NewHTMLWithStatus ¶
func NewHTMLWithStatus(template *template.Template, data interface{}, code HTTPStatus) *Response
NewHTMLWithStatus returns a html response generated by template and data with status code
func NewJSONWithStatus ¶
func NewJSONWithStatus(v interface{}, code HTTPStatus) *Response
NewJSONWithStatus returns a JSON formatted response with the given status code
func NewRedirect ¶
NewRedirect returns *Responose for redirect
func NewRedirectWithStatus ¶
func NewRedirectWithStatus(url string, status HTTPStatus) *Response
NewRedirectWithStatus returns *Responose for redirect
func NewResponse ¶
NewResponse retuurns a *Response to write body content
func NewResponseWithStatus ¶
func NewResponseWithStatus(body Body, status HTTPStatus) *Response
NewResponseWithStatus retuurns a *Response to write body content with a custom status code.
func NewTextWithStatus ¶
func NewTextWithStatus(s interface{}, code HTTPStatus) *Response
NewTextWithStatus returns a text formatted response with the given status code