helper

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abbreviate added in v0.23.2

func Abbreviate(s string) string

Used by templates to generate abbreviation including numbers inside the code

func ArrayToMap added in v0.15.6

func ArrayToMap[T any](m map[string]T, e []T, f func(T) string) map[string]T

ArrayToMap converts an array to a map using a key function

func BaseName added in v0.24.0

func BaseName(src string) string

BaseName returns the last element of path.

func Contains added in v0.15.6

func Contains(a string, b string) bool

Contains checks if a string contains a substring case insensitive

func CopyDir added in v0.15.6

func CopyDir(src, dst string) error

func CopyFile

func CopyFile(source, target string) error

func Dir added in v0.12.1

func Dir(path string) string

func EachTicked added in v0.26.3

func EachTicked[T any](ctx context.Context, items []T, fn func(T), dt time.Duration)

EachTicked calls fn for each item in items every dt.

func ExpandFiles added in v0.24.0

func ExpandFiles(rootDir string, filter ExtFilter, inputs ...string) ([]string, error)

func ExpandInputs added in v0.24.0

func ExpandInputs(rootDir string, inputs ...string) ([]string, error)

func Ext added in v0.15.1

func Ext(file string) string

func FallbackDir added in v0.24.0

func FallbackDir(name string, dirs ...string) (string, error)

FallbackDir returns the first dir that exists.

func FindDocuments

func FindDocuments(path string) ([]string, error)

func GetDocumentType added in v0.20.0

func GetDocumentType(path string) string

func GetFreePort added in v0.8.0

func GetFreePort() (int, error)

func HasExt added in v0.15.1

func HasExt(file string, exts ...string) bool

func HttpPost added in v0.24.0

func HttpPost(url string, contentType string, data []byte) error

func HttpPostJson added in v0.24.0

func HttpPostJson(url string, data interface{}) error

func IsDir

func IsDir(elem string) bool

func IsDocument

func IsDocument(path string) bool

func IsExist

func IsExist(path string) bool

func IsFile

func IsFile(path string) bool

func Join added in v0.9.0

func Join(elem ...string) string

func JoinMaps added in v0.38.0

func JoinMaps(maps ...map[string]interface{}) map[string]interface{}

func ListDir added in v0.16.0

func ListDir(path string)

func MakeDir added in v0.12.1

func MakeDir(dst string) error

func MakeIdGenerator added in v0.8.0

func MakeIdGenerator(prefix string) func() string

func MakeIntIdGenerator added in v0.19.0

func MakeIntIdGenerator() func() uint64

func MapToArray added in v0.15.6

func MapToArray[T any](m map[string]T) []T

MapToArray converts a map to an array

func Must added in v0.12.0

func Must(err error)

func NewUUID added in v0.26.3

func NewUUID() string

func ParseJson

func ParseJson(data []byte, out any) error

func ParseYaml

func ParseYaml(data []byte, out any) error

func ReadDocument

func ReadDocument(path string, v any) error

func ReadYamlFromData

func ReadYamlFromData(in []byte, out any) error

func ReadYamlFromString added in v0.31.0

func ReadYamlFromString(in string, out any) error

func RemoveDir added in v0.12.0

func RemoveDir(dst string) error

func ScanFile added in v0.24.0

func ScanFile(fn string) ([][]byte, error)

func ScanNDJSON added in v0.24.0

func ScanNDJSON[T any](r io.Reader) ([]T, error)

Scan scans a reader line by line and writes to the writer.

func ScanNDJSONFile added in v0.24.0

func ScanNDJSONFile[T any](path string) ([]T, error)

ScanFile scans a file line by line and writes to the writer.

func SelectValue added in v0.38.0

func SelectValue(m map[string]interface{}, selector string) interface{}

func ToSlice added in v0.22.0

func ToSlice(v any) []any

func WaitForInterrupt added in v0.24.0

func WaitForInterrupt(cancel func())

WaitForInterrupt handles SIGINT and SIGTERM signals. It cancels the context when a signal is received.

func WriteDocument

func WriteDocument(path string, v any) error

func WriteFile added in v0.12.1

func WriteFile(dst string, data []byte) error

func YamlToJson

func YamlToJson(in []byte) ([]byte, error)

Types

type Emitter added in v0.45.0

type Emitter[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewEmitter added in v0.45.0

func NewEmitter[T any]() *Emitter[T]

func (*Emitter[T]) Add added in v0.45.0

func (e *Emitter[T]) Add(name string, handler EventHandler[T]) func()

func (*Emitter[T]) Emit added in v0.45.0

func (e *Emitter[T]) Emit(name string, data T)

func (*Emitter[T]) Remove added in v0.45.0

func (e *Emitter[T]) Remove(name string, id string)

type EventHandler added in v0.24.0

type EventHandler[T any] func(data T)

type ExtFilter added in v0.24.0

type ExtFilter func(string) bool

type HTTPSender added in v0.24.0

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

func NewHTTPSender added in v0.24.0

func NewHTTPSender(url string) *HTTPSender

func (*HTTPSender) Send added in v0.24.0

func (s *HTTPSender) Send(data []byte, contentType string) error

Send sends the data to the sender.

func (*HTTPSender) SendValue added in v0.24.0

func (s *HTTPSender) SendValue(value interface{}) error

SendValue sends the value as json to the sender.

func (*HTTPSender) Write added in v0.24.0

func (s *HTTPSender) Write(data []byte) (int, error)

Write writes the event to the sender. This is used to implement the io.Writer interface. Data is send as json.

type Hook added in v0.45.0

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

func NewHook added in v0.45.0

func NewHook[T any]() *Hook[T]

NewHook creates a new Hook.

func (*Hook[T]) AddHook added in v0.45.0

func (h *Hook[T]) AddHook(fn func(*T)) func()

AddHook adds the handler to the end of the list

func (*Hook[T]) Clear added in v0.45.0

func (h *Hook[T]) Clear()

Clear clears the list of handlers

func (*Hook[T]) ConnectHook added in v0.45.0

func (h *Hook[T]) ConnectHook(other *Hook[T]) func()

ConnectHook connects the hook to another hook

func (*Hook[T]) FireHook added in v0.45.0

func (h *Hook[T]) FireHook(event *T, oneOf ...func(*T))

FireHook calls all handlers in the list

func (*Hook[T]) Len added in v0.45.0

func (h *Hook[T]) Len() int

Len returns the number of handlers

func (*Hook[T]) PreAddHook added in v0.45.0

func (h *Hook[T]) PreAddHook(fn func(*T)) func()

PreAddHook adds the handler to the beginning of the list

func (*Hook[T]) RemoveAllHooks added in v0.45.0

func (h *Hook[T]) RemoveAllHooks()

RemoveAllHooks removes all handlers

type Iterator added in v0.26.3

type Iterator[T any] interface {
	Next() (T, bool)
	HasNext() bool
}

func NewIterator added in v0.26.3

func NewIterator[T any](items []T) Iterator[T]

type SenderControl added in v0.24.0

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

func NewSenderControl added in v0.24.0

func NewSenderControl[T any](repeat int, sleep time.Duration) *SenderControl[T]

func (*SenderControl[T]) Run added in v0.24.0

func (t *SenderControl[T]) Run(items []T, send func(T) error) error

Jump to

Keyboard shortcuts

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