jsonresponse

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

README

HTTP JSON Response for Go

GoDoc Build Status

Installation

Run go get resenje.org/jsonresponse from command line.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultContentTypeHeader is the value of if "Content-Type" header
	// in HTTP response.
	DefaultContentTypeHeader = "application/json; charset=utf-8"
	// EscapeHTML specifies whether problematic HTML characters
	// should be escaped inside JSON quoted strings.
	EscapeHTML = false
)
View Source
var ErrEmptyRequestBody = errors.New("empty request body")

ErrEmptyRequestBody is returned from UnmarshalRequestBody when request body is empty either if Content-Length header is 0 or JSON decoder returns EOF.

Functions

func Accepted

func Accepted(w http.ResponseWriter, response interface{})

Accepted writes a response with status code 202.

func BadGateway

func BadGateway(w http.ResponseWriter, response interface{})

BadGateway writes a response with status code 502.

func BadRequest

func BadRequest(w http.ResponseWriter, response interface{})

BadRequest writes a response with status code 400.

func Conflict

func Conflict(w http.ResponseWriter, response interface{})

Conflict writes a response with status code 409.

func Continue

func Continue(w http.ResponseWriter, response interface{})

Continue writes a response with status code 100.

func Created

func Created(w http.ResponseWriter, response interface{})

Created writes a response with status code 201.

func ExpectationFailed

func ExpectationFailed(w http.ResponseWriter, response interface{})

ExpectationFailed writes a response with status code 417.

func Forbidden

func Forbidden(w http.ResponseWriter, response interface{})

Forbidden writes a response with status code 403.

func Found

func Found(w http.ResponseWriter, response interface{})

Found writes a response with status code 302.

func GatewayTimeout

func GatewayTimeout(w http.ResponseWriter, response interface{})

GatewayTimeout writes a response with status code 504.

func Gone

func Gone(w http.ResponseWriter, response interface{})

Gone writes a response with status code 410.

func HTTPVersionNotSupported

func HTTPVersionNotSupported(w http.ResponseWriter, response interface{})

HTTPVersionNotSupported writes a response with status code 505.

func InternalServerError

func InternalServerError(w http.ResponseWriter, response interface{})

InternalServerError writes a response with status code 500.

func LengthRequired

func LengthRequired(w http.ResponseWriter, response interface{})

LengthRequired writes a response with status code 411.

func MethodNotAllowed

func MethodNotAllowed(w http.ResponseWriter, response interface{})

MethodNotAllowed writes a response with status code 405.

func MovedPermanently

func MovedPermanently(w http.ResponseWriter, response interface{})

MovedPermanently writes a response with status code 301.

func MultipleChoices

func MultipleChoices(w http.ResponseWriter, response interface{})

MultipleChoices writes a response with status code 300.

func NonAuthoritativeInfo

func NonAuthoritativeInfo(w http.ResponseWriter, response interface{})

NonAuthoritativeInfo writes a response with status code 203.

func NotAcceptable

func NotAcceptable(w http.ResponseWriter, response interface{})

NotAcceptable writes a response with status code 406.

func NotFound

func NotFound(w http.ResponseWriter, response interface{})

NotFound writes a response with status code 404.

func NotImplemented

func NotImplemented(w http.ResponseWriter, response interface{})

NotImplemented writes a response with status code 501.

func NotModified

func NotModified(w http.ResponseWriter, response interface{})

NotModified writes a response with status code 304.

func OK

func OK(w http.ResponseWriter, response interface{})

OK writes a response with status code 200.

func PartialContent

func PartialContent(w http.ResponseWriter, response interface{})

PartialContent writes a response with status code 206.

func PaymentRequired

func PaymentRequired(w http.ResponseWriter, response interface{})

PaymentRequired writes a response with status code 402.

func PermanentRedirect

func PermanentRedirect(w http.ResponseWriter, response interface{})

PermanentRedirect writes a response with status code 308.

func PreconditionFailed

func PreconditionFailed(w http.ResponseWriter, response interface{})

PreconditionFailed writes a response with status code 412.

func PreconditionRequired

func PreconditionRequired(w http.ResponseWriter, response interface{})

PreconditionRequired writes a response with status code 428.

func ProxyAuthRequired

func ProxyAuthRequired(w http.ResponseWriter, response interface{})

ProxyAuthRequired writes a response with status code 407.

func RequestEntityTooLarge

func RequestEntityTooLarge(w http.ResponseWriter, response interface{})

RequestEntityTooLarge writes a response with status code 413.

func RequestHeaderFieldsTooLarge

func RequestHeaderFieldsTooLarge(w http.ResponseWriter, response interface{})

RequestHeaderFieldsTooLarge writes a response with status code 431.

func RequestTimeout

func RequestTimeout(w http.ResponseWriter, response interface{})

RequestTimeout writes a response with status code 408.

func RequestURITooLong

func RequestURITooLong(w http.ResponseWriter, response interface{})

RequestURITooLong writes a response with status code 414.

func RequestedRangeNotSatisfiable

func RequestedRangeNotSatisfiable(w http.ResponseWriter, response interface{})

RequestedRangeNotSatisfiable writes a response with status code 416.

func ResetContent

func ResetContent(w http.ResponseWriter, response interface{})

ResetContent writes a response with status code 205.

func Respond

func Respond(w http.ResponseWriter, statusCode int, response interface{})

Respond writes a JSON-encoded body to http.ResponseWriter.

func SeeOther

func SeeOther(w http.ResponseWriter, response interface{})

SeeOther writes a response with status code 303.

func ServiceUnavailable

func ServiceUnavailable(w http.ResponseWriter, response interface{})

ServiceUnavailable writes a response with status code 503.

func SwitchingProtocols

func SwitchingProtocols(w http.ResponseWriter, response interface{})

SwitchingProtocols writes a response with status code 101.

func Teapot

func Teapot(w http.ResponseWriter, response interface{})

Teapot writes a response with status code 418.

func TemporaryRedirect

func TemporaryRedirect(w http.ResponseWriter, response interface{})

TemporaryRedirect writes a response with status code 307.

func TooManyRequests

func TooManyRequests(w http.ResponseWriter, response interface{})

TooManyRequests writes a response with status code 429.

func Unauthorized

func Unauthorized(w http.ResponseWriter, response interface{})

Unauthorized writes a response with status code 401.

func UnavailableForLegalReasons

func UnavailableForLegalReasons(w http.ResponseWriter, response interface{})

UnavailableForLegalReasons writes a response with status code 451.

func UnmarshalRequestBody

func UnmarshalRequestBody(w http.ResponseWriter, r *http.Request, v interface{}) error

UnmarshalRequestBody unmarshals JSON encoded HTTP request body into an arbitrary interface. In case of error, it writes appropriate JSON-encoded response to http.ResponseWriter, so the calling handler should not write new data if this function returns error.

func UnsupportedMediaType

func UnsupportedMediaType(w http.ResponseWriter, response interface{})

UnsupportedMediaType writes a response with status code 415.

func UpgradeRequired

func UpgradeRequired(w http.ResponseWriter, response interface{})

UpgradeRequired writes a response with status code 426.

func UseProxy

func UseProxy(w http.ResponseWriter, response interface{})

UseProxy writes a response with status code 305.

Types

type MessageResponse

type MessageResponse struct {
	Message string `json:"message,omitempty"`
	Code    int    `json:"code,omitempty"`
}

MessageResponse is the response structure that will be written by Respond function if respond argument is nil.

func NewMessage

func NewMessage(message string) *MessageResponse

NewMessage returns MessageResponse with a provided textual message.

Jump to

Keyboard shortcuts

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