utils

package
v0.0.0-...-4bd82ba Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const Default = "default"

Variables

This section is empty.

Functions

func DispatchEvent

func DispatchEvent(logger *logrus.Logger, events ...domain_events.IEvent)

func GetEnv

func GetEnv(name string) string

func GetEnvWithDefaultValue

func GetEnvWithDefaultValue(name string, defaultValue string) string

func GetOauthPrivateKeyFile

func GetOauthPrivateKeyFile() ([]byte, error)

func GetOauthPublicKeyFile

func GetOauthPublicKeyFile() ([]byte, error)

func GetRootPath

func GetRootPath() string

func GracefulShutdown

func GracefulShutdown(ctx context.Context, log *logrus.Logger, timeout time.Duration, ops map[string]GracefulOperation) <-chan struct{}

func LoadEnv

func LoadEnv() error

func NewLogInstance

func NewLogInstance(logOptions ...LogOption) *logrus.Logger

NewLogInstance ...

func RandomString

func RandomString(n int) string

func ToKebabCase

func ToKebabCase(str string) string

func ToSnakeCase

func ToSnakeCase(str string) string

Types

type DefaultFieldHook

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

func (*DefaultFieldHook) Fire

func (h *DefaultFieldHook) Fire(e *logrus.Entry) error

func (*DefaultFieldHook) Levels

func (h *DefaultFieldHook) Levels() []logrus.Level

type GracefulOperation

type GracefulOperation func(ctx context.Context) error

type IResponse

type IResponse[TData, ITMeta any] interface {
	MakeMetaData(message string, data map[string]ITMeta, page *int, perPage *int, totalPage *int)
	BuildResponse() *response[TData, ITMeta]
}

func NewResponse

func NewResponse[T, TMeta any](data T) IResponse[T, TMeta]

type IWorkerPool

type IWorkerPool interface {
	Run(ctx context.Context)
	WaitWorker()
	GetResults() []result
	AddTask(task task)
	SetWorkerNumber(total int)
	GetTotalSuccessJob() int
}

func NewWorkerPool

func NewWorkerPool() IWorkerPool

type LogConfig

type LogConfig struct {
	IsProduction bool
	Environment  string
	LogFileName  string
	Fields       map[string]interface{}
}

type LogOption

type LogOption func(*LogConfig)

func IsProduction

func IsProduction(isProd bool) LogOption

func LogAdditionalFields

func LogAdditionalFields(fields map[string]interface{}) LogOption

func LogEnvironment

func LogEnvironment(env string) LogOption

func LogName

func LogName(logname string) LogOption

type Meta

type Meta[T any] struct {
	Message    string       `json:"message,omitempty"`
	Additional map[string]T `json:"additional,omitempty"`
	Page       *int         `json:"page,omitempty"`
	PerPage    *int         `json:"per_page,omitempty"`
	TotalPage  *int         `json:"total_page,omitempty"`
}

type WorkerPool

type WorkerPool struct {
	TotalSuccessJob int
	// contains filtered or unexported fields
}

func (*WorkerPool) AddTask

func (wa *WorkerPool) AddTask(task task)

func (*WorkerPool) GetResults

func (wa *WorkerPool) GetResults() []result

func (*WorkerPool) GetTotalSuccessJob

func (wa *WorkerPool) GetTotalSuccessJob() int

func (*WorkerPool) Run

func (wa *WorkerPool) Run(ctx context.Context)

func (*WorkerPool) SetWorkerNumber

func (wa *WorkerPool) SetWorkerNumber(total int)

func (*WorkerPool) WaitWorker

func (wa *WorkerPool) WaitWorker()

Jump to

Keyboard shortcuts

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