dd

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 14 Imported by: 2

README

dd-go

Documentation

Index

Constants

View Source
const (
	DEFAULT_QUEUE_SIZE = 1024
)

Variables

This section is empty.

Functions

func DirExists

func DirExists(path *string) bool

DirExists -

func FileExists

func FileExists(path *string) bool

FileExists -

func MillisecondsTimeVal added in v0.2.0

func MillisecondsTimeVal(v *int64) time.Time

MillisecondsTimeVal converts an int64 pointer to a time.Time value representing milliseconds sinch Epoch or time.Time{} if the pointer is nil.

func Ptr

func Ptr[T any](v T) *T

Ptr Generic type version returns a pointer to the value passed in

func PtrMap added in v0.2.0

func PtrMap[T any](src map[string]T) map[string]*T

PtrMap Generic type version converts a string map of T values into a string map of T pointers

func PtrSlice added in v0.2.0

func PtrSlice[T any](src []T) []*T

PtrSlice Generic type version converts a slice of T values into a slice of T pointers

func SecondsTimeVal added in v0.2.0

func SecondsTimeVal(v *int64) time.Time

SecondsTimeVal converts an int64 pointer to a time.Time value representing seconds since Epoch or time.Time{} if the pointer is nil.

func TimeUnixMilli

func TimeUnixMilli(t time.Time) int64

TimeUnixMilli returns a Unix timestamp in milliseconds from "January 1, 1970 UTC". The result is undefined if the Unix time cannot be represented by an int64. Which includes calling TimeUnixMilli on a zero Time is undefined.

This utility is useful for service API's such as CloudWatch Logs which require their unix time values to be in milliseconds.

See Go stdlib https://golang.org/pkg/time/#Time.UnixNano for more information.

func Val

func Val[T any](v *T) T

Val Generic type version returns the value of the pointer passed in or default value of this type if pointer is nil

func ValD added in v0.2.0

func ValD[T any](v *T, defaultVal T) T

ValD Generic type version returns the value of the pointer passed in or return |defaultVal| if pointer is nil

func ValMap added in v0.2.0

func ValMap[T any](src map[string]*T) map[string]T

ValMap Generic type version converts a string map of T pointers into a string map of T values

func ValSlice added in v0.2.0

func ValSlice[T any](src []*T) []T

ValSlice Generic type version converts a slice of T pointers into a slice of T values

Types

type Closure

type Closure func() any

An implement of Closure(https://en.wikipedia.org/wiki/Closure_(computer_programming))

func Bind0

func Bind0[R any](f func() R) *Closure

func Bind1

func Bind1[T any, R any](f func(T) R, p T) *Closure

func Bind2

func Bind2[T1, T2, R any](f func(T1, T2) R, p1 T1, p2 T2) *Closure

func Bind3

func Bind3[T1, T2, T3, R any](
	f func(T1, T2, T3) R,
	p1 T1, p2 T2, p3 T3) *Closure

func Bind4

func Bind4[T1, T2, T3, T4, R any](
	f func(T1, T2, T3, T4) R,
	p1 T1, p2 T2, p3 T3, p4 T4) *Closure

func Bind5

func Bind5[T1, T2, T3, T4, T5, R any](
	f func(T1, T2, T3, T4, T5) R,
	p1 T1, p2 T2, p3 T3, p4 T4, p5 T5) *Closure

func Bind6

func Bind6[T1, T2, T3, T4, T5, T6, R any](
	f func(T1, T2, T3, T4, T5, T6) R,
	p1 T1, p2 T2, p3 T3, p4 T4, p5 T5, p6 T6) *Closure

func Bind7

func Bind7[T1, T2, T3, T4, T5, T6, T7, R any](
	f func(T1, T2, T3, T4, T5, T6, T7) R,
	p1 T1, p2 T2, p3 T3, p4 T4, p5 T5, p6 T6, p7 T7) *Closure

func Bind8

func Bind8[T1, T2, T3, T4, T5, T6, T7, T8, R any](
	f func(T1, T2, T3, T4, T5, T6, T7, T8) R,
	p1 T1, p2 T2, p3 T3, p4 T4, p5 T5, p6 T6, p7 T7, p8 T8) *Closure

func (*Closure) Run

func (f *Closure) Run() any

Implement |Task| interface

type ConfigLoader added in v0.2.0

type ConfigLoader[T any] interface {
	Load(out *T) error
}

func NewINILoader added in v0.2.5

func NewINILoader[T any](path, section *string) ConfigLoader[T]

func NewJSONLoader added in v0.2.0

func NewJSONLoader[T any](path *string) ConfigLoader[T]

func NewYAMLLoader added in v0.2.0

func NewYAMLLoader[T any](path *string) ConfigLoader[T]

type FileReader added in v0.2.0

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

func (*FileReader) Close added in v0.2.0

func (r *FileReader) Close() error

Close implement io.Closer interface

func (*FileReader) Read added in v0.2.0

func (r *FileReader) Read(data []byte) (int, error)

Read implement io.Reader interface

type INILoader added in v0.2.5

type INILoader[T any] struct {
	// contains filtered or unexported fields
}

func (*INILoader[T]) Load added in v0.2.5

func (loader *INILoader[T]) Load(out *T) error

type JSONLoader added in v0.2.0

type JSONLoader[T any] struct {
	// contains filtered or unexported fields
}

func (*JSONLoader[T]) Load added in v0.2.0

func (loader *JSONLoader[T]) Load(out *T) error

type JSONValue

type JSONValue map[string]any

JSONValue is a representation of a grab bag type that will be marshaled into a json string. This type can be used just like any other map.

Example:

values := dd.JSONValue{
	"Foo": "Bar",
}
values["Baz"] = "Qux"

type LevelLogger added in v0.2.0

type LevelLogger interface {
	Logger
	Error(...any)
	Warn(...any)
	Info(...any)
	Debug(...any)
}

A LevelLogger is a interface to log message with level and can be filter by logger

func NewLevelLogger added in v0.2.0

func NewLevelLogger(level LogLevel) LevelLogger

NewLevelLogger returns a LevelLogger which will write log to stdout, and filter with LogLevel

type LogLevel added in v0.2.0

type LogLevel int
const (
	ERROR LogLevel = iota
	WARN
	INFO
	DEBUG
)

type Logger

type Logger interface {
	Log(...any)
}

A Logger is a minimalistic interface to log messages to. Should be used to provide custom logging writers use.

func NewDefaultLogger

func NewDefaultLogger() Logger

NewDefaultLogger returns a Logger which will write log messages to stdout, and use same formatting runes as the stdlib log.Logger

type LoggerFunc

type LoggerFunc func(...any)

A LoggerFunc is a convenience type to convert a function taking a variadic list of arguments and wrap it so the Logger interface can be used.

func (LoggerFunc) Log

func (f LoggerFunc) Log(args ...any)

Log calls the wrapped function with the arguments provided

type Task

type Task interface {
	Run() any
}

Task It represent a running unit in |TaskRunner|

type TaskRunner

type TaskRunner interface {
	Post(task Task) error

	PostDelay(task Task, delay time.Duration) error
}

TaskRunner It represent a runner than runs a |Task| asynchronous

type WorkerPoolRunner

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

func DefaultWorkerPoolRunner added in v0.1.1

func DefaultWorkerPoolRunner() *WorkerPoolRunner

func NewWorkerPoolRunner

func NewWorkerPoolRunner(options *WorkerPoolRunnerOptions) *WorkerPoolRunner

func (*WorkerPoolRunner) Post

func (runner *WorkerPoolRunner) Post(task Task) error

Post - Implement |TaskRunner| interface, enqueue task

func (*WorkerPoolRunner) PostDelay added in v0.1.1

func (runner *WorkerPoolRunner) PostDelay(task Task, delay time.Duration) error

func (*WorkerPoolRunner) StopAndWait

func (runner *WorkerPoolRunner) StopAndWait() error

StopAndWait - Cancel all the running goroutines and wait for them exit

type WorkerPoolRunnerOptions added in v0.1.1

type WorkerPoolRunnerOptions struct {
	QueueSize   uint
	Concurrency uint
	Logger      LevelLogger
}

type YAMLLoader added in v0.2.0

type YAMLLoader[T any] struct {
	// contains filtered or unexported fields
}

func (*YAMLLoader[T]) Load added in v0.2.0

func (loader *YAMLLoader[T]) Load(out *T) error

Jump to

Keyboard shortcuts

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