utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckImageContentType

func CheckImageContentType(image *multipart.FileHeader) error

func CheckImageFileContentType

func CheckImageFileContentType(fileContent []byte) (string, error)

Check that the image contentType is in the allowed list

func ErrResponseWithLog

func ErrResponseWithLog(ctx echo.Context, logger logger.Logger, err error) error

Error response with logging error for echo context

func ErrorsWithStack

func ErrorsWithStack(err error) string

ErrorsWithStack returns a string contains error messages in the stack with its stack trace levels for given error

func ErrorsWithoutStack

func ErrorsWithoutStack(err error, format bool) string

ErrorsWithoutStack just returns error messages without its callstack

func GetConfigPath

func GetConfigPath(configPath string) string

Get config path for local or docker

func GetCtxWithReqID

func GetCtxWithReqID(c echo.Context) (context.Context, context.CancelFunc)

Get ctx with timeout and request id from echo context

func GetHasMore

func GetHasMore(currentPage int, totalCount int, pageSize int) bool

Get has more

func GetIPAddress

func GetIPAddress(c echo.Context) string

Get user ip address

func GetImageContentType

func GetImageContentType(image []byte) (string, bool)

func GetImageExtension

func GetImageExtension(image *multipart.FileHeader) (string, error)

func GetRequestCtx

func GetRequestCtx(c echo.Context) context.Context

Get context with request id

func GetRequestID

func GetRequestID(c echo.Context) string

Get request id from echo context

func GetTotalPages

func GetTotalPages(totalCount int, pageSize int) int

Get total pages int

func GetUniqFileName

func GetUniqFileName(userID string, fileExtension string) string

func IsAllowedImageContentType

func IsAllowedImageContentType(image []byte) bool

func IsAllowedImageHeader

func IsAllowedImageHeader(image *multipart.FileHeader) bool

func LogResponseError

func LogResponseError(ctx echo.Context, logger logger.Logger, err error)

Error response with logging error for echo context

func ReadImage

func ReadImage(ctx echo.Context, field string) (*multipart.FileHeader, error)

Read an image and return a multipart file

func ReadRequest

func ReadRequest(ctx echo.Context, request interface{}) error

Read request body and validate

func ValidateStruct

func ValidateStruct(ctx context.Context, s interface{}) error

Validate struct fields

Types

type Claims

type Claims struct {
	Email string `json:"email"`
	ID    string `json:"id"`
	jwt.StandardClaims
}

JWT Claims struct

type PaginationQuery

type PaginationQuery struct {
	Size    int    `json:"size,omitempty"`
	Page    int    `json:"page,omitempty"`
	OrderBy string `json:"orderBy,omitempty"`
}

Pagination query params

func GetPaginationFromCtx

func GetPaginationFromCtx(c echo.Context) (*PaginationQuery, error)

Get pagination query struct from

func (*PaginationQuery) GetLimit

func (q *PaginationQuery) GetLimit() int

Get limit

func (*PaginationQuery) GetOffset

func (q *PaginationQuery) GetOffset() int

Get offset

func (*PaginationQuery) GetOrderBy

func (q *PaginationQuery) GetOrderBy() string

Get OrderBy

func (*PaginationQuery) GetPage

func (q *PaginationQuery) GetPage() int

Get OrderBy

func (*PaginationQuery) GetQueryString

func (q *PaginationQuery) GetQueryString() string

func (*PaginationQuery) GetSize

func (q *PaginationQuery) GetSize() int

Get OrderBy

func (*PaginationQuery) SetOrderBy

func (q *PaginationQuery) SetOrderBy(orderByQuery string)

Set order by

func (*PaginationQuery) SetPage

func (q *PaginationQuery) SetPage(pageQuery string) error

Set page number

func (*PaginationQuery) SetSize

func (q *PaginationQuery) SetSize(sizeQuery string) error

Set page size

type ReqIDCtxKey

type ReqIDCtxKey struct{}

ReqIDCtxKey is a key used for the Request ID in context

Jump to

Keyboard shortcuts

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