jsonhttp

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package jsonhttp provides helper functions to write JSON responses to http.ResponseWriter and read JSON bodies from http.Request.

Index

Constants

This section is empty.

Variables

View Source
var MaxPostSize int64 = 1048576

MaxPostSize is the maximum number of bytes that ParseBody reads from an http.Request.Body.

Functions

func ParseBody

func ParseBody(r *http.Request, v interface{}) (int, error)

ParseBody reads a JSON-encoded body from a http.Request and unmarshals it into the provided object.

func Render

func Render(w http.ResponseWriter, httpStatus int, v interface{})

Render writes a JSON-encoded object to a http.ResponseWriter, as well as a HTTP status code.

func RenderError

func RenderError(w http.ResponseWriter, httpStatus int, err error)

RenderError writes an error, wrapped in the Message field of a JSON-encoded object to a http.ResponseWriter, as well as a HTTP status code. If the status code is 0, RenderError tries to guess the proper HTTP status code from the error type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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