responsex

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Data

func Data(c echo.Context, data interface{}) error

Data shotcut response with data

func R

func R(c echo.Context, response *Response) error

R response code

func SetStatusMap

func SetStatusMap(m map[StatusCode]string)

SetStatusMap set global status map

Types

type Error

type Error struct {
	Status     int
	HttpStatus int
	Message    string
	Internal   error
}

Error is a responsex error

func NewError

func NewError(status int, message string) *Error

NewError create new error instance

func Status

func Status(status StatusCode, message ...string) *Error

Status transform status to error with message

func StatusMessage

func StatusMessage(status StatusCode, args ...interface{}) *Error

StatusMessage transform status with formated message (with arguments)

func (*Error) Error

func (e *Error) Error() string

Error implements error interface

func (*Error) SetHttpStatus

func (e *Error) SetHttpStatus(httpStatus int) *Error

SetHttpStatus set http status code

func (*Error) SetInternal

func (e *Error) SetInternal(internal error) *Error

SetInternal set internal / cause error

type Response

type Response struct {
	HttpStatus int         `json:"-"`
	Status     int         `json:"status"`
	Message    string      `json:"message"`
	Data       interface{} `json:"data,omitempty"`
}

Response represents RESTful response

func New

func New(status int, msg string, data interface{}) *Response

New create new response

func (*Response) SetData

func (t *Response) SetData(data interface{}) *Response

SetData set response data

func (*Response) SetHttpStatus

func (t *Response) SetHttpStatus(httpStatus int) *Response

SetHttpStatus set http response status

func (*Response) SetMsg

func (t *Response) SetMsg(msg string) *Response

SetMsg set response message

func (*Response) SetStatus

func (t *Response) SetStatus(status int) *Response

SetStatus set response body status code

type StatusCode

type StatusCode int

StatusCode represents the status code

Jump to

Keyboard shortcuts

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