jsonresp

package
Version: v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

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)

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

func WriteResponse

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

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