helper

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 21 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 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 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 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 EventEmitter added in v0.24.0

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

EventEmitter is a typed event emitter.

func NewEventEmitter added in v0.24.0

func NewEventEmitter[T any]() *EventEmitter[T]

NewEventEmitter creates a new event emitter.

func (*EventEmitter[T]) Clear added in v0.24.0

func (e *EventEmitter[T]) Clear()

Clear removes all handlers.

func (*EventEmitter[T]) Emit added in v0.24.0

func (e *EventEmitter[T]) Emit(evt T)

Emit emits an event to all handlers.

func (*EventEmitter[T]) On added in v0.24.0

func (e *EventEmitter[T]) On(handler EventHandler[T])

On registers a new event handler.

type EventHandler added in v0.24.0

type EventHandler[T any] func(evt T)

EventHandler callback for an event.

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 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