utilities

package
v0.0.0-...-9b6346a Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound         = errors.New("Not found")
	ErrNoCtxMetaData    = errors.New("No ctx metadata")
	ErrInvalidSessionId = errors.New("Invalid session id")
	ErrEmailExists      = errors.New("Email already exists")
)

Functions

func AttachTokenToContext

func AttachTokenToContext(ctx context.Context, authToken string) context.Context

AttachTokenToContext inputs ctx and an auth token and returns ctx with token attached

func BoolToStr

func BoolToStr(in bool) string

BoolToStr converts a bool to a string value

func CheckObjectID

func CheckObjectID(hexID string) bool

CheckObjectID checks whether a hexID is null or now

func ErrorResponse

func ErrorResponse(err error, msg string) error

ErrorResponse GRPC Error response

func GenerateObjectID

func GenerateObjectID() string

GenerateObjectID for index keying records of data

func GetTokenFromContext

func GetTokenFromContext(ctx context.Context) (string, error)

GetTokenFromContext parses an auth token from content metadata

func MapGRPCErrCodeToHttpStatus

func MapGRPCErrCodeToHttpStatus(code codes.Code) int

MapGRPCErrCodeToHttpStatus Map GRPC errors codes to http status

func NewAPILogger

func NewAPILogger(cfg *config.Configuration) *apiLogger

NewAPILogger Logger constructor

func ParseGRPCErrStatusCode

func ParseGRPCErrStatusCode(err error) codes.Code

ParseGRPCErrStatusCode Parse error and get code

func StrToBool

func StrToBool(in string) bool

StrToBool converts a string to a bool

Types

type JWTError

type JWTError struct {
	Message string `json:"message"`
}

JWTError is a struct that is used to contain a json encoded error message for any JWT related errors

type JsonErr

type JsonErr struct {
	Code int    `json:"code"`
	Text string `json:"text"`
}

JsonErr structures a standard error to return

type Logger

type Logger interface {
	InitLogger()
	Debug(args ...interface{})
	Debugf(template string, args ...interface{})
	Info(args ...interface{})
	Infof(template string, args ...interface{})
	Warn(args ...interface{})
	Warnf(template string, args ...interface{})
	Error(args ...interface{})
	Errorf(template string, args ...interface{})
	DPanic(args ...interface{})
	DPanicf(template string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(template string, args ...interface{})
	Printf(template string, args ...interface{})
}

Logger methods interface

type Pagination

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

Pagination query params

func NewPaginationQuery

func NewPaginationQuery(size int, page int) *Pagination

func (*Pagination) GetHasMore

func (q *Pagination) GetHasMore(totalCount int) bool

GetHasMore Get has more

func (*Pagination) GetLimit

func (q *Pagination) GetLimit() int

GetLimit Get limit

func (*Pagination) GetOffset

func (q *Pagination) GetOffset() int

GetOffset Get offset

func (*Pagination) GetOrderBy

func (q *Pagination) GetOrderBy() string

GetOrderBy Get OrderBy

func (*Pagination) GetPage

func (q *Pagination) GetPage() int

GetPage Get OrderBy

func (*Pagination) GetQueryString

func (q *Pagination) GetQueryString() string

GetQueryString get query string

func (*Pagination) GetSize

func (q *Pagination) GetSize() int

GetSize Get OrderBy

func (*Pagination) GetTotalPages

func (q *Pagination) GetTotalPages(totalCount int) int

GetTotalPages Get total pages int

func (*Pagination) SetOrderBy

func (q *Pagination) SetOrderBy(orderByQuery string)

SetOrderBy Set order by

func (*Pagination) SetPage

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

SetPage Set page number

func (*Pagination) SetSize

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

SetSize Set page size

Jump to

Keyboard shortcuts

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