apputils

package
v0.1.132 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package apputils has a collection of methods useful for app

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToFloat64

func ConvertToFloat64(val interface{}) (float64, error)

ConvertToFloat64 takes any value and returns the converted float64 value if it can be converted.

func ConvertToFloat64Slice

func ConvertToFloat64Slice(input any) ([]float64, error)

ConvertToFloat64Slice attempts to convert an `any` to a slice of float64 if possible.

func IsInList

func IsInList[T any](list []T, item T) bool

IsInList returns whether item is in list.

func IsMap

func IsMap(value interface{}) bool

IsMap returns whether value is a map type.

func IsMatchForRegex

func IsMatchForRegex(x, y any) (bool, error)

IsMatchForRegex first validates 'x' and 'y' are strings and then returns whether 'y' is a match on regex 'x'.

func IsNumber

func IsNumber(value interface{}) bool

IsNumber takes any value and returns whether its a numeric type.

func IsSlice

func IsSlice(value interface{}) bool

IsSlice returns whether value is a list of any type.

Types

type Eval

type Eval struct {
	Operator EvalOperator `bson:"operator" json:"operator" mapstructure:"operator"`
	Value    any          `bson:"value"    json:"value"    mapstructure:"value"`
}

Eval is a typed representation of logic that can be evaluated.

type EvalOperator

type EvalOperator string

EvalOperator is a typed representation of an operator used to describe a condition for a trigger event.

var (
	// LessThan is a typed representation of the < operator.
	LessThan EvalOperator = "lt"
	// LessThanOrEqual is a typed representation of the <= operator.
	LessThanOrEqual EvalOperator = "lte"
	// GreaterThan is a typed representation of the > operator.
	GreaterThan EvalOperator = "gt"
	// GreaterThanOrEqual is a typed representation of the >= operator.
	GreaterThanOrEqual EvalOperator = "gte"
	// Equal is a typed representation of the == operator.
	Equal EvalOperator = "eq"
	// NotEqual is a typed representation of the != operator.
	NotEqual EvalOperator = "neq"
	// Regex is a typed representation of the regular expression operator.
	Regex EvalOperator = "regex"
)

func (EvalOperator) Evaluate

func (operator EvalOperator) Evaluate(readingValue, conditionValue any) (bool, error)

Evaluate returns whether 'readingValue' is [insert operator here] 'conditionValue'.

func (EvalOperator) IsValidOperator

func (operator EvalOperator) IsValidOperator(validOperators ...EvalOperator) bool

IsValidOperator returns whether the operator is in the list of provided valid operators.

func (EvalOperator) ToReadableString

func (operator EvalOperator) ToReadableString() string

ToReadableString returns a string representation of an evaluable operator.

Jump to

Keyboard shortcuts

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