response

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package response implements helpers for JSON responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataResponse

type DataResponse struct {
	Code int         `json:"-"`
	Data interface{} `json:"data"`
}

DataResponse describes a JSON response containing resource data:

{
	data: {...}
}

If resource data is an array of objects, the data key will be an array:

{
	data: [...]
}

func NewDataResponse

func NewDataResponse(resources interface{}) DataResponse

NewDataResponse returns a new DataResponse

func (DataResponse) WithCode

func (r DataResponse) WithCode(code int) DataResponse

WithCode sets the code for the response and returns the DataResponse

func (DataResponse) Write

func (r DataResponse) Write(w http.ResponseWriter)

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ErrorResponse describes a JSON error response with the following body:

{
	"code": 404,
	"message": "not found"
}

func NewErrorResponse

func NewErrorResponse(code int, message string) ErrorResponse

NewErrorResponse returns a new ErrorResponse

func (ErrorResponse) Write

func (e ErrorResponse) Write(w http.ResponseWriter)

Jump to

Keyboard shortcuts

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