utils

package
v0.0.0-...-3c0f6d4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureJWTCookie

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

Configure JWT cookie

func ConfigureSessionCookie

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

Configure Session Cookie

func DeleteSessionCookie

func DeleteSessionCookie(c echo.Context, sessionName string)

Delete session

func ExtractJWTFromRequest

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

Extract JWT from Request

func ExtratcBearerToken

func ExtratcBearerToken(r *http.Request) string

Extract bearer token from request Authorization header

func GenerateJWTToken

func GenerateJWTToken(user *entity.User, config *config.Config) (string, error)

Generate new JWT Token

func GetHasMore

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

Get has more

func GetIP

func GetIP(c echo.Context) string

Get user IP address

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 GetUserFromCtx

func GetUserFromCtx(ctx context.Context) (*entity.User, error)

Get User from context

func ReadRequest

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

Read request body and validate

func ValidateIsOwner

func ValidateIsOwner(ctx context.Context, creatorID string, 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"`
	jwt.StandardClaims
}

JWT Claims struct

type PaginationQuery

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

Pagination with out offset

func GetPaginationFromCtx

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

Get pagination query struct from

func (*PaginationQuery) GetDifference

func (q *PaginationQuery) GetDifference() int

Get difference

func (*PaginationQuery) GetLimit

func (q *PaginationQuery) GetLimit() int

Get limit

func (*PaginationQuery) GetOrderBy

func (q *PaginationQuery) GetOrderBy() string

Get order by

func (*PaginationQuery) GetPage

func (q *PaginationQuery) GetPage() int

Get page

func (*PaginationQuery) GetSize

func (q *PaginationQuery) GetSize() int

Get size

func (*PaginationQuery) SetDifference

func (q *PaginationQuery) SetDifference(differenceQuery string) error

Set difference

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 from 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