response

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write added in v0.0.17

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

Types

type ErrorCode added in v0.0.34

type ErrorCode string
const (
	ErrCodeMalformedBody    ErrorCode = "malformed_body"
	ErrCodeInvalidRequest   ErrorCode = "invalid_request"
	ErrCodeRouteNotFound    ErrorCode = "route_not_found"
	ErrCodeResourceNotFound ErrorCode = "resource_not_found"
	ErrCodeMethodNotAllowed ErrorCode = "method_not_allowed"
	ErrCodeConflict         ErrorCode = "conflict"
	ErrCodeInternal         ErrorCode = "internal"
)

type ErrorMessage added in v0.0.34

type ErrorMessage string
const (
	ErrMgsMalformedBody    ErrorMessage = "A malformed body was provided"
	ErrMgsInvalidRequest   ErrorMessage = "An invalid request was provided"
	ErrMgsRouteNotFound    ErrorMessage = "The route cannot be found"
	ErrMgsResourceNotFound ErrorMessage = "The resource cannot be found"
	ErrMgsMethodNotAllowed ErrorMessage = "The method is not allowed"
	ErrMgsConflict         ErrorMessage = "A conflic has been detected"
	ErrMgsInternal         ErrorMessage = "An internal error has occurred"
)

type Response added in v0.0.16

type Response struct {
	// Shared common fields.
	Status  int               `json:"-"`
	Headers map[string]string `json:"-"`

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

	// Failure specific fields.
	Code    ErrorCode         `json:"code,omitempty"`
	Message ErrorMessage      `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