common

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter added in v1.0.22

func Filter(rules [][]FilterRule, properties map[string]string) (bool, error)

Filter checks whether the properties adhere to the rules provided.

The rules are a two-dimensional array where the first dimension is joined by a logical disjunction ("OR") and the second one by a logical conjunction ("AND").

The properties can be the for example the name and MAC address of a device.

func Getenv

func Getenv(key, fallback string) string

Getenv reads the value from environment variable named by key. If the key is not defined as environment variable the default string is returned.

func Loop

func Loop(function func(), interval time.Duration) func()

Loop wraps a function in an endless loop and calls the function in the defined interval.

func LoopWithParam added in v1.0.16

func LoopWithParam[T any](function func(T), param T, interval time.Duration) func()

func Ptr

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

Ptr delivers the pointer of any constant value like Ptr("foo")

func RunOnce

func RunOnce(function func(), id any)

RunOnce starts a function if this function not currently running. RunOnce knows, with function is currently running (identified by id) and skips starting the function again.

func RunOnceWithParam added in v1.0.18

func RunOnceWithParam[T any](function func(T), param T, id any)

RunOnceWithParam starts a function if this function not currently running. RunOnce knows, with function is currently running (identified by id) and skips starting the function again.

func StoppableLoop added in v1.0.16

func StoppableLoop(function func() bool, interval time.Duration) func()

StoppableLoop wraps a function in a loop and calls the function in the defined interval until the function return false.

func StoppableLoopWithParam added in v1.0.16

func StoppableLoopWithParam[T any](function func(T) bool, param T, interval time.Duration) func()

func StructToMap

func StructToMap(data any) map[string]interface{}

StructToMap converts a struct to map of struct properties

func UnmarshalFile

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

UnmarshalFile returns the content of the file as object of type T

func Val added in v1.0.63

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

Val return the value from pointer or if nil the default value

func WaitFor

func WaitFor(functions ...func())

WaitFor helps to start multiple functions in parallel and waits until all functions are completed.

func WaitForWithOs added in v1.0.11

func WaitForWithOs(functions ...func())

WaitForWithOs helps to start multiple functions in parallel and waits until all functions are completed or if system signals termination

Types

type FilterRule added in v1.0.22

type FilterRule struct {
	Parameter string
	Regex     string
}

Jump to

Keyboard shortcuts

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