response

package
v0.0.0-...-c9ee09a Latest Latest
Warning

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

Go to latest
Published: May 25, 2016 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ErrorMissingNameParameter   = 1
	ErrorInvalidIdParameter     = 2
	ErrorInvalidEnumParameter   = 3
	ErrorInvalidLimitParameter  = 4
	ErrorInvalidOffsetParameter = 5
)

Custom error details

It is suggested you actually type the int value here, as opposed to using the iota pattern generally used with constants. These integer values actually have meaning, and API consumers are to use the values. Using actual ints will prevent accidental value changes in the event something is inserted in the middle of the list. In addition, this makes it easier to lookup what an error code means from it's int value.

After adding a value to this list, you must always add it to the errorDetailText map.

Variables

This section is empty.

Functions

func ErrorDetailText

func ErrorDetailText(code int) string

ErrorText returns a code's associated error text

Types

type ErrorDetail

type ErrorDetail struct {
	Code int    `json:"code"`
	Text string `json:"text"`
}

type Response

type Response struct {
	Context      echo.Context  `json:"-"`
	Success      bool          `json:"success"`
	StatusCode   int           `json:"status_code"`
	StatusText   string        `json:"status_text"`
	ErrorDetails []ErrorDetail `json:"error_details"`
	Content      interface{}   `json:"content"`
}

func New

func New(c echo.Context) *Response

New instantiates a new Response struct and attaches the Echo context. It returns the Response struct.

func (*Response) AddErrorDetail

func (r *Response) AddErrorDetail(code int)

AddError appends an error to the response via an Error Code.

func (*Response) AddErrorDetails

func (r *Response) AddErrorDetails(codes []int)

AddErrorDetails appends multiple errors to the response via Error Codes.

func (*Response) Render

func (r *Response) Render()

Render sets the appropriate status, converts the content to JSON and passes it to Echo's context for rendering.

func (*Response) SetResponse

func (r *Response) SetResponse(code int, content interface{})

SetResponse sets the response status code and content.

Jump to

Keyboard shortcuts

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