utils

package
v0.0.0-...-05bba3d Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package utils provides utilities to handle common activities such as logging, error handling, etc.

Index

Constants

This section is empty.

Variables

Log serves as a wrapper around the underlying logging implementation to provide a consistent logging framework independent of underlying logger

View Source
var LogMiddleware echo.MiddlewareFunc

LogMiddleware serves as a wrapper around the underlying middleware logging implementation to provide a consistent logging framework independent of underlying logger

Functions

func ArrayContains

func ArrayContains(arr []string, str string) bool

func IndexOf

func IndexOf(element string, arr []string) int

func IsUniqueConstraintError

func IsUniqueConstraintError(err error, constraintName string) bool

IsUniqueConstraintError checks if the given error and constraint name represents a unique constraint

func LoggerInit

func LoggerInit(lvl string)

LoggerInit initializes the logger

func RemoveIndex

func RemoveIndex(arr []string, index int) []string

Types

type APIError

type APIError struct {
	Model   string        `json:"model"`
	Code    int           `json:"code"`
	Message string        `json:"message"`
	Errors  []interface{} `json:"errors"`
}

func DBError

func DBError(model interface{}, fieldName string, err error, dberr error) APIError

func NewError

func NewError(code int, err error) APIError

func ResourceNotFound

func ResourceNotFound() APIError

func Unauthorized

func Unauthorized() APIError

func ValidatorError

func ValidatorError(model interface{}, vErrors []ValidationError) APIError

type ValidationError

type ValidationError struct {
	Message             string
	Field               string
	Condition           string
	ConditionParameters string
	ReceivedValue       interface{}
}

ValidationError represents a structured validation error object to be used on responses

func GetValidationErrors

func GetValidationErrors(err validator.ValidationErrors) []ValidationError

type Validator

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

Validator defines the structure of the Validator object

func NewValidator

func NewValidator() *Validator

NewValidator returns create a new validator object

func (*Validator) Validate

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

Validate runs validation over a given object. Validation rules are defined on the model (struct) object.

Jump to

Keyboard shortcuts

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