verr

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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 BaseError

type BaseError struct {
	Message string `json:"message"`
}

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 NewStatus

func NewStatus() *Status

func NewStatusInternal

func NewStatusInternal(message error) *Status

func (*Status) Created

func (i *Status) Created(message string)

func (*Status) Done

func (i *Status) Done(message string)

func (*Status) Error

func (i *Status) Error() string

func (*Status) Failed

func (i *Status) Failed(message string)

func (*Status) Internal

func (i *Status) Internal(message string)

func (*Status) Open

func (i *Status) Open(message string)

func (*Status) Process

func (i *Status) Process(message string)

func (*Status) Response

func (i *Status) Response() (int, interface{})

func (*Status) Set

func (i *Status) Set(t string, message string) *Status

func (*Status) ValidateDone

func (i *Status) ValidateDone() error

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)

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

func (*Validator) New

func (i *Validator) New(v *validator.Validate) *Validator

func (*Validator) Validate

func (i *Validator) Validate(valid interface{}) error

Jump to

Keyboard shortcuts

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