webhelp.v1: gopkg.in/webhelp.v1/whjson Index | Files

package whjson

import "gopkg.in/webhelp.v1/whjson"

Package whjson provides some nice utilities for dealing with JSON-based APIs, such as a good JSON wherr.Handler.


Package Files



var (
    // ErrHandler provides a good wherr.Handler. It will return a JSON object
    // like `{"err": "message"}` where message is filled in with
    // errhttp.GetErrorBody. The status code is set with errhttp.GetStatusCode.
    ErrHandler = wherr.HandlerFunc(errHandler)

func Render Uses

func Render(w http.ResponseWriter, r *http.Request, value interface{})

Render will render JSON `value` like `{"resp": <value>}`, falling back to ErrHandler if no error handler was registered and an error is encountered. This is good for making sure your API is always returning usefully namespaced JSON objects that are clearly differentiated from error responses.

Package whjson imports 7 packages (graph). Updated 2017-06-08. Refresh now. Tools for package owners.