api

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgInternalServer   = "An internal error has occurred"
	MsgInvalidRequest   = "An invalid request was provided"
	MsgResourceNotFound = "The resource cannot be found"
	MsgRouteNotFound    = "The route cannot be found"
	MsgMethodNotAllowed = "The method is not allowed"
	MsgInvalidValue     = "Invalid value"
	MsgUnknownField     = "Unknown field"
)

Variables

View Source
var (
	ErrInternalServer      = errors.New("internal server")
	ErrResourceNotFound    = errors.New("resource not found")
	ErrResourceNotAffected = errors.New("resource not affected")
)

Functions

func Respond

func Respond(w http.ResponseWriter, r Response) error

Types

type Response

type Response struct {
	// Shared common fields.
	Code    int               `json:"-"`
	Headers map[string]string `json:"-"`
	Action  string            `json:"action,omitempty"`

	// Success specific fields.
	Data interface{} `json:"data,omitempty"`
	Meta interface{} `json:"meta,omitempty"`

	// Failure specific fields.
	Message string            `json:"message,omitempty"`
	Errors  map[string]string `json:"errors,omitempty"`
}

Jump to

Keyboard shortcuts

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