verr

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 15 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)
)

Variables

View Source
var ErrJSONBind = errors.New("json can't bind to the interface")
View Source
var ErrJSONValidate = errors.New("json is not valid")
View Source
var ErrMongoDelete = errors.New("no delete document")
View Source
var ErrMongoUpdate = errors.New("no updated document")
View Source
var InternalServerErrorMsg = echo.NewHTTPError(http.StatusInternalServerError, BaseError{Message: "internal_server_error"})

InternalServerErrorMsg is an error that handles internal server error response

View Source
var LogLevel = "debug"

LogLevel can be set by SetLogLevel. Default value is debug

Functions

func GetEnvWithLog added in v0.1.1

func GetEnvWithLog(key string) (string, bool)

GetEnvWithLog Validate .env Variables

func GetIntEnvWithLog added in v0.1.1

func GetIntEnvWithLog(key string) (int, bool)

GetIntEnvWithLog Validate .env Variables

func InsertErrorResponse added in v0.1.10

func InsertErrorResponse(c echo.Context, err error) error

func InternalServerError added in v0.1.1

func InternalServerError(ctx context.Context, err error) error

InternalServerError with logs

func JSONValidate

func JSONValidate(c echo.Context, i interface{}) error

JSONValidate validates a json bind in echo.Context. The interface i is used for validation. If the c.Bind(i) or the validation returns errors the function return an APIError.

func ListErrorResponse added in v0.1.10

func ListErrorResponse(c echo.Context, err error) error

func LogError added in v0.1.1

func LogError(ctx context.Context, err error, lvl string)

LogError prints error in service logs

func MongoDeleteErr added in v0.1.10

func MongoDeleteErr(err error, result *mongo.DeleteResult) error

func MongoDeleteOneError added in v0.1.1

func MongoDeleteOneError(ctx context.Context, err error, coll string, result *mongo.DeleteResult) error

MongoDeleteOneError handles error response and logging for collection.deleteOne() function.

func MongoErrorResponse added in v0.1.12

func MongoErrorResponse(err error, collection string) *echo.HTTPError

func MongoFindOneError added in v0.1.1

func MongoFindOneError(ctx context.Context, err error, coll string) error

MongoFindOneError handles error response and logging for collection.findOne() function.

func MongoInsertOneError added in v0.1.1

func MongoInsertOneError(ctx context.Context, err error, coll string) error

MongoInsertOneError handles error response and logging for collection.insertOne() function.

func MongoUpdateErr added in v0.1.10

func MongoUpdateErr(err error, result *mongo.UpdateResult) error

func MongoUpdateOneError added in v0.1.1

func MongoUpdateOneError(ctx context.Context, err error, coll string, result *mongo.UpdateResult) error

MongoUpdateOneError handles error response and logging for collection.deleteOne() function.

func SetLogLevel added in v0.1.1

func SetLogLevel(l string)

SetLogLevel can be used for set LogLevel variable

func ToSnakeCase added in v1.0.1

func ToSnakeCase(str string) string

Types

type APIError

type APIError struct {
	Code  int
	Body  interface{}
	Error error
	Line  int
	File  string
	Level bool
}

APIError represents the return value of all database controllers in case of an error.

func NewAPIError

func NewAPIError(err error) *APIError

NewAPIError catches there context of calling and creates an APIError contains this informations. File is set to the name of the file and Line to the line in file NewAPIError was called from.

func (*APIError) Conflict

func (a *APIError) Conflict(m string) *APIError

Conflict extend APIError for http status 409 Conflict and adds a message m that can response to client.

func (*APIError) Forbidden

func (a *APIError) Forbidden(m string) *APIError

Forbidden extend APIError for http status Forbidden and adds a message m that can response to client.

func (*APIError) InternalServerError

func (a *APIError) InternalServerError() *APIError

InternalServerError extend APIError for http status 500 Internal Server Error

func (*APIError) Log

func (a *APIError) Log(c echo.Context)

Log print APIError to server logs

func (*APIError) LogNats added in v0.1.1

func (a *APIError) LogNats()

LogNats print APIError to server logs

func (*APIError) NotFound

func (a *APIError) NotFound(m string) *APIError

NotFound extend APIError for http status 404 Not Found and adds a message m that can response to client.

func (*APIError) Unauthorized

func (a *APIError) Unauthorized() *APIError

Unauthorized extend APIError for http status 401 Unauthorized and adds a message m that can response to client.

type BaseError added in v0.1.1

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

type JSONError

type JSONError struct {
	Error []string `json:"error"`
}

JSONError represents a json validation error. Used om return of JSONErrorResponse:w

func JSONErrorResponse

func JSONErrorResponse(err error) (jList []JSONError)

JSONErrorResponse creates a response for json validation error.

type JSONValidator

type JSONValidator struct {
	Validator *validator.Validate
}

JSONValidator validation struct using for JSON

func (*JSONValidator) Validate

func (cv *JSONValidator) Validate(i interface{}) error

Validate extend JSONValidator with Validate function.

type MongoBase added in v0.1.1

type MongoBase struct {
	Message string `json:"message"`
	Coll    string `json:"collection,omitempty"`
}

MongoBase represents response type basic mongo error with collection involved.

type MongoConflict added in v0.1.1

type MongoConflict struct {
	Message string `json:"message"`
	Coll    string `json:"collection"`
	Value   string `json:"value"`
}

MongoConflict represents the reponse type for mongo database Conficts.

type ResponseError

type ResponseError struct {
	Message string                 `json:"message"`
	Data    map[string]interface{} `json:"data,omitempty"`
}

ResponseError represents the json body of an error response.

Jump to

Keyboard shortcuts

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