utils

package
v0.0.0-...-2f27ceb Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 16 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 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 *domain.User, 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 GetRequestCtx

func GetRequestCtx(c echo.Context) context.Context

Get context with request id

func GetRequestID

func GetRequestID(c echo.Context) string

Get RequestID from echo context

func GetTotalPages

func GetTotalPages(totalCount int, pageSize int) int

Get total pages int

func GetUserFromCtx

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

Get user from context

func LogResponseError

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

Error response with logging error for echo context

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 {
	Username string `json:"username"`
	ID       string `json:"id"`
	jwt.RegisteredClaims
}

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