utils

package
v0.0.0-...-9808740 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 23 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)

func ConfigureJWTCookie

func ConfigureJWTCookie(cfg *config.Config, jwtToken string) *http.Cookie

Configure jwt cookie

func CreateSessionCookie

func CreateSessionCookie(cfg *config.Config, session string) *http.Cookie

Configure jwt cookie

func DeleteSessionCookie

func DeleteSessionCookie(c echo.Context, sessionName string)

Delete session

func ErrResponseWithLog

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

Error response with logging error for echo context

func ExtractBearerToken

func ExtractBearerToken(r *http.Request) string

Extract bearer token from request Authorization header

func ExtractJWTFromRequest

func ExtractJWTFromRequest(r *http.Request) (map[string]interface{}, error)

Extract JWT From Request

func GenerateJWTToken

func GenerateJWTToken(user *models.UserWithRole, config *config.Config) (string, error)

Generate new JWT Token

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 GetUserFromCtx

func GetUserFromCtx(ctx context.Context) (*models.UserWithRole, error)

Get user from context

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)

func ReadRequest

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

Read request body and validate

func SanitizeRequest

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

Read sanitize and validate request

func ValidateIsOwner

func ValidateIsOwner(ctx context.Context, creatorID int, logger logger.Logger) error

Validate is user from owner of content

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"`
	Role  int    `json:"role"`
	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

type UserCtxKey

type UserCtxKey struct{}

UserCtxKey is a key used for the User object in the context

Jump to

Keyboard shortcuts

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