Documentation ¶
Index ¶
- Constants
- Variables
- func BindAndValidate(c echo.Context, i interface{}) error
- func ErrorHandler(err error, c echo.Context)
- func ResponseMongo(i *vmdb.MongoError) (int, interface{})
- type BaseError
- type ErrorResponse
- type Status
- func (i *Status) Created(message string)
- func (i *Status) Done(message string)
- func (i *Status) Error() string
- func (i *Status) Failed(message string)
- func (i *Status) Internal(message string)
- func (i *Status) Open(message string)
- func (i *Status) Process(message string)
- func (i *Status) Response() (int, interface{})
- func (i *Status) Set(t string, message string) *Status
- func (i *Status) ValidateDone() error
- type ValidationError
- type Validator
Constants ¶
View Source
const ( //ColorRed use string(ColorRed) ColorRed = "\033[31m" //ColorGreen use string(ColorGreen) ColorGreen = "\033[32m" //ColorYellow use string(ColorYellow) ColorYellow = "\033[33m" //ColorBlue use string(ColorBlue) ColorBlue = "\033[34m" //ColorPurple use string(ColorPurple) ColorPurple = "\033[35m" //ColorCyan use string(ColorCyan) ColorCyan = "\033[36m" //ColorWhite use string(ColorWhite) ColorWhite = "\033[37m" //ErrorWithColor is a red string "Error: " ErrorWithColor = string(ColorRed) + "Error: " + string(ColorWhite) //WarningWithColor is a yellow string "Warning: " WarningWithColor = string(ColorYellow) + "Warning: " + string(ColorWhite) //SuccessWithColor is a green string "Success: " SuccessWithColor = string(ColorGreen) + "Success: " + string(ColorWhite) )
View Source
const StatusCREATED = "created"
View Source
const StatusDONE = "done"
View Source
const StatusFAILED = "failed"
View Source
const StatusINTERNAL = "internal_error"
View Source
const StatusOPEN = "open"
View Source
const StatusPROCESS = "process"
Variables ¶
View Source
var InternalServerErrorMsg = echo.NewHTTPError(http.StatusInternalServerError, BaseError{Message: "internal_server_error"})
InternalServerErrorMsg is an error that handles internal server error response
Functions ¶
func BindAndValidate ¶
func BindAndValidate(c echo.Context, i interface{}) error
func ErrorHandler ¶
func ErrorHandler(err error, c echo.Context)
HTTPErrorHandler handles echo.HTTPError and return the correct response.
func ResponseMongo ¶
func ResponseMongo(i *vmdb.MongoError) (int, interface{})
Response return the ErrorResponse for handling in httpErrorHandler
Types ¶
type ErrorResponse ¶
type ErrorResponse struct { Status int `json:"-"` Message string `json:"message"` Body interface{} `json:"body,omitempty"` Coll string `json:"collection,omitempty"` Model string `json:"model,omitempty"` }
Response represents an response json in case of an error.
func BadRequest ¶
func BadRequest(message string, body ...interface{}) (int, *ErrorResponse)
BadRequest creates an echo.HTTPError with the status http.StatusBadRequest
func Conflict ¶
func Conflict(message string, body ...interface{}) (int, *ErrorResponse)
Conflict creates an echo.HTTPError with the status http.StatusConflict
func InternalServerError ¶
func InternalServerError() (int, ErrorResponse)
InternalServerError creates an echo.HTTPError with the status http.StatusInternalServerError
func NotFound ¶
func NotFound(message string, body ...interface{}) (int, *ErrorResponse)
NotFound creates an echo.HTTPError with the status http.StatusNotFound
type Status ¶
type Status struct { StatusType string `bson:"status_type" json:"status_type"` StatusMessage string `bson:"status_message" json:"status_message"` }
func NewStatusInternal ¶
func (*Status) ValidateDone ¶
type ValidationError ¶
type ValidationError struct {
Errors []string `json:"errors"`
}
func (*ValidationError) Bind ¶
func (i *ValidationError) Bind(err error)
func (*ValidationError) Error ¶
func (i *ValidationError) Error() string
func (*ValidationError) Response ¶
func (i *ValidationError) Response() (int, interface{})
func (*ValidationError) Valid ¶
func (i *ValidationError) Valid(err error)
Click to show internal directories.
Click to hide internal directories.