common

package
v0.0.0-...-946fd12 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ID         = "id"
	UserId     = "user_id"
	PropertyId = "property_id"
	ImageId    = "image_id"
)

Variables

View Source
var (
	ErrNotFound        = New("NOT_FOUND", http.StatusNotFound)
	ErrExists          = New("EXIST_ERROR", http.StatusBadRequest)
	ErrInternal        = New("INTERNAL_ERROR", http.StatusInternalServerError)
	ErrTimeout         = New("REQUEST_TIMEOUT", http.StatusRequestTimeout)
	ErrUnauthorized    = New("UNAUTHORIZED", http.StatusUnauthorized)
	ErrBind            = New("COULD_NOT_PARSE_AND_BIND_REQUEST", http.StatusBadRequest)
	ErrMapping         = New("COULD_NOT_MAP_DATA", http.StatusUnprocessableEntity)
	ErrValidate        = New("REQUEST_VALIDATION_FAILURE", http.StatusBadRequest)
	ErrAccessForbidden = New("ACCESS_FORBIDDEN", http.StatusForbidden)
)

Error codes Only common use codes should be in the library, implementation-specific errors should be in other packages.

Functions

func ErrorHandler

func ErrorHandler(logger *zap.SugaredLogger) func(err error, c echo.Context)

func IDFromContext

func IDFromContext(c echo.Context, key string) (int, error)

func IDFromPath

func IDFromPath(c echo.Context, key string) (int, error)

func ProcessDomainError

func ProcessDomainError(ctx echo.Context, err error) error

func UserID

func UserID(ctx echo.Context) (int, error)

Types

type BaseHandler

type BaseHandler struct {
}

func (BaseHandler) ValidateRequest

func (n BaseHandler) ValidateRequest(ctx echo.Context, req interface{}) (bool, error)

type BaseSearchRequest

type BaseSearchRequest struct {
	Page int `json:"page" validate:"number,max=100000" json:"page,omitempty"`
	Size int `json:"size" validate:"number,max=1000" json:"size,omitempty"`
	Sort int `json:"sort" validate:"omitempty,number,min=1,max=15" json:"size,omitempty"`

} // @name BaseSearchRequest

type DefaultResponse

type DefaultResponse struct {
	Count      int         `json:"count,omitempty"`
	TotalCount int         `json:"totalCount,omitempty"`
	Data       interface{} `json:"data"`

} // @name DefaultResponseContainer

type EmptyResponse

type EmptyResponse struct {

} // @name EmptyResponse

type Error

type Error struct {
	Err  string `json:"error"`
	Code int    `json:"-"`
	// contains filtered or unexported fields
}

func New

func New(message string, code int) Error

func (Error) Error

func (e Error) Error() string

Error implements error interface

func (Error) Is

func (e Error) Is(err error) bool

Is reports whether any error in the chain matches target.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns the next error in the error chain.

func (Error) Wrap

func (e Error) Wrap(err error) Error

Wrap saves error to the chain.

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"error,omitempty"`

} // @name ErrorResponse

type ErrorValidateResponse

type ErrorValidateResponse struct {
	Err         string       `json:"error"`
	FieldErrors []FieldError `json:"fieldErrors"`

} // @name ValidationErrorResponse

func NewErrorValidateResponse

func NewErrorValidateResponse(message string, fieldErrors validator.ValidationErrors) ErrorValidateResponse

type FieldError

type FieldError struct {
	Error string `json:"error"`
	Field string `json:"field"`
	Tag   string `json:"tag"`
}

type Handler

type Handler interface {
	AddRoutes(e *echo.Group, m ...echo.MiddlewareFunc)
	ValidateRequest(ctx echo.Context, req interface{}) (bool, error)
}

type ModelDateTime

type ModelDateTime struct {
	CreatedAt int64 `json:"createdAt"`
	UpdatedAt int64 `json:"updatedAt"`
}

Jump to

Keyboard shortcuts

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