utils

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxLimit defines query max value to field limit
	MaxLimit uint64 = 100
)

Variables

View Source
var File_protos_error_proto protoreflect.FileDescriptor

Functions

func FormatValuesInUp

func FormatValuesInUp(input interface{}, validateNullField ...bool) (cols []string, vals []interface{}, err error)

FormatValuesInUp format columns and values ​​for an insert or update query

func GenerateToken

func GenerateToken(secret string, ts int64) (otp string, err error)

GenerateToken generate an OTP token

func GetUrlQrCode

func GetUrlQrCode(projectName, otpToken, userName *string) (url string)

GetUrlQrCode returns the url of qr code to configure the otp

func MakePagination

func MakePagination[T any](query *squirrel.SelectBuilder, p *Params) (res []T, next *bool, err error)

MakePagination constructs pagination data for a given database query

func PanicRecovery

func PanicRecovery(msg interface{}) (err error)

PanicRecovery handles recovered panics

func Pointer

func Pointer[T any](value T) *T

Pointer returns a pointer reference

func RandomString

func RandomString(length int) string

RandomString generates a random string of specified length.

The generated string is cryptographically random and matches [A-Za-z0-9]+ (aka. it's transparent to URL-encoding).

func TypeConverter

func TypeConverter[T any](data any) (*T, error)

TypeConverter converts all data to a destination data output.

func ValidateToken

func ValidateToken(token, otp *string) (err error)

ValidateToken validates if the otp is valid

Types

type ErrorGRPC

type ErrorGRPC struct {
	Location *string `protobuf:"bytes,1,opt,name=Location,proto3,oneof" json:"Location,omitempty"`
	RawError *string `protobuf:"bytes,2,opt,name=RawError,proto3,oneof" json:"RawError,omitempty"`
	Error    *string `protobuf:"bytes,3,opt,name=Error,proto3,oneof" json:"Error,omitempty"`
	Code     *uint64 `protobuf:"varint,4,opt,name=Code,proto3,oneof" json:"Code,omitempty"`
	// contains filtered or unexported fields
}

func (*ErrorGRPC) Descriptor deprecated

func (*ErrorGRPC) Descriptor() ([]byte, []int)

Deprecated: Use ErrorGRPC.ProtoReflect.Descriptor instead.

func (*ErrorGRPC) GetCode

func (x *ErrorGRPC) GetCode() uint64

func (*ErrorGRPC) GetError

func (x *ErrorGRPC) GetError() string

func (*ErrorGRPC) GetLocation

func (x *ErrorGRPC) GetLocation() string

func (*ErrorGRPC) GetRawError

func (x *ErrorGRPC) GetRawError() string

func (*ErrorGRPC) ProtoMessage

func (*ErrorGRPC) ProtoMessage()

func (*ErrorGRPC) ProtoReflect

func (x *ErrorGRPC) ProtoReflect() protoreflect.Message

func (*ErrorGRPC) Reset

func (x *ErrorGRPC) Reset()

func (*ErrorGRPC) String

func (x *ErrorGRPC) String() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(cfg *config.Config) *Logger

NewLogger logger constructor

func (*Logger) DPanic

func (l *Logger) DPanic(args ...interface{})

func (*Logger) DPanicf

func (l *Logger) DPanicf(template string, args ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(template string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(template string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(template string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(template string, args ...interface{})

func (*Logger) InitLogger

func (l *Logger) InitLogger()

InitLogger initialize zap logger

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

func (*Logger) Panicf

func (l *Logger) Panicf(template string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(template string, args ...interface{})

func (*Logger) ZapLogger

func (l *Logger) ZapLogger() *zap.Logger

type NoContent

type NoContent struct{}

NoContent dummy struct for empty responses

type Params

type Params struct {
	// Fields returns as request queries
	Fields []string

	// Filters returns all filters of a request in map format
	Filters map[string][]string

	// Limit limit is used to set the size of a paginated list
	Limit uint64

	// Offset offset is used to determine which page
	// should be in the paginated list
	Offset uint64

	// Total Total is used to fetch the total
	// amount of a paginated list
	Total bool
}

Params used for requests when some controls params are allowed

func NewParams

func NewParams() Params

NewParams builds an empty dummy `Params` object for utility usage

func ParseParams

func ParseParams(ctx *gin.Context) (params Params, err error)

ParseParams receives the gin.Context and parse the query params for the request

func (*Params) AddFilter

func (p *Params) AddFilter(name string, values ...string) *Params

AddFilter add a filter to request params

func (*Params) ClearFilters

func (p *Params) ClearFilters() *Params

ClearFilters clear the filters from the request params

func (*Params) HasFilter

func (p *Params) HasFilter(filter string) (hasFilter bool)

HasFilter returns true if the filter is searched for in the filter list

func (*Params) RemoveFilters

func (p *Params) RemoveFilters(filters ...string) *Params

RemoveFilters remove filter values

Jump to

Keyboard shortcuts

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