jsonresp

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2018 License: BSD-3-Clause Imports: 4 Imported by: 6

README

JSON Response

The json-resp package contains a small set of functions that are used to marshall and unmarshall response data and errors in JSON format.

Quick Start

Install dep and the CircleCI Local CLI. See the Dependency Management and Continuous Integration sections below for more detail.

Use dep to populate the vendor/ directory:

dep ensure

To build and test:

circleci build

Dependency Management

This package uses dep for dependency management. Install it by following the directions for your platform here.

Continuous Integration

This package uses CircleCI for Continuous Integration (CI). It runs automatically on commits and pull requests involving a protected branch. All CI checks must pass before a merge to a proected branch can be performed.

The CI checks are typically run in the cloud without user intervention. If desired, the CI checks can also be run locally using the CircleCI Local CLI.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadResponse

func ReadResponse(r io.Reader, v interface{}) error

ReadResponse reads a JSON response, and unmarshals the supplied data.

func WriteError

func WriteError(w http.ResponseWriter, error string, code int) error

WriteError encodes the supplied error in a response, and writes to w.

func WriteResponse

func WriteResponse(w http.ResponseWriter, data interface{}, code int) error

WriteResponse encodes the supplied data in a response, and writes to w.

Types

type Error

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

Error describes an error condition.

func NewError

func NewError(code int, message string) *Error

NewError returns an error that contains the given code and message.

func (*Error) Error

func (e *Error) Error() string

type Response

type Response struct {
	Data  interface{} `json:"data,omitempty"`
	Error *Error      `json:"error,omitempty"`
}

Response is the top level container of all of our REST API responses.

Jump to

Keyboard shortcuts

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