utils

package
v0.0.0-...-0ad5b3e Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Regexp2MatchTimeout       = "REGEXP2_MATCH_TIMEOUT"
	DefaultRegex2MatchTimeout = time.Second
)
View Source
const NamingCharacterSet = "abcdefghijklmnopqrstuvwxyz1234567890"

Variables

View Source
var ErrFieldNotExist = errors.New("field does not exist")
View Source
var NumberOfCharacter = int64(len(NamingCharacterSet))

Functions

func AsString

func AsString(value interface{}) (string, bool)

AsString tries to convert an interface{} into a string, and returns its value and an integer indicating whether it succeeded or not.

func DateOf

func DateOf(v time.Time) time.Time

DateOf returns time without hour, minute, and second.

func EscapeRegex

func EscapeRegex(v string) string

func FindAllStringSubmatchMapWithRegexExpression

func FindAllStringSubmatchMapWithRegexExpression(re RegexExpression, s string) []map[string]string

FindAllStringSubmatchMapWithRegexExpression returns a slice of maps containing the values of the named subexpressions of all matches of the regular expression re in s. A return value of nil indicates no match.

func FindStringSubmatchMapWithRegexExpression

func FindStringSubmatchMapWithRegexExpression(re RegexExpression, s string) map[string]string

FindStringSubmatchMapWithRegexExpression returns a map containing the values of the named subexpressions of the lefmost match of the regular expression re in s. A return value of nil indicates no match.

func GetField

func GetField(object interface{}, fieldPath string) (interface{}, error)

GetField returns the value of a field of an object or a map, given the field's name as a string. Multiple field names may be chained, separated by dots:

GetField(alarm_value, "State.Value")

An error is returned if the field does not exist. If the field is a pointer, it will be dereferenced before being returned. Note that GetField cannot return map keys that contain a dot.

func InterfaceSliceToStringSlice

func InterfaceSliceToStringSlice(v []any) ([]string, bool)

func IsStringSlice

func IsStringSlice(arg any) ([]string, bool)

func MatchWithRegexExpression

func MatchWithRegexExpression(re RegexExpression, s string) bool

func MaxTime

func MaxTime(left, right time.Time) time.Time

MaxTime returns max time between arguments.

func MinDuration

func MinDuration(left, right time.Duration) time.Duration

func MinTime

func MinTime(left, right time.Time) time.Time

MinTime returns minimal time between arguments.

func NewID

func NewID() string

NewID generate an uuid

func RandBase64String

func RandBase64String(n int) (string, error)

RandBase64String generates a random base64 string by generated n bytes

func RandString

func RandString(n int) string

RandString generate a random string

func ToObjectIDHex

func ToObjectIDHex(s string) string

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase changes case of string to snake case.

func TruncateString

func TruncateString(s string, chars int) string

func Unique

func Unique(s []string) []string

Types

type RegexExpression

type RegexExpression interface {
	Match([]byte) bool
	String() string
}

func NewRegexExpression

func NewRegexExpression(expr string) (RegexExpression, error)

NewRegexExpression todo move to separate package

type WrapperBuiltInRegex

type WrapperBuiltInRegex struct {
	*regexp.Regexp
}

type WrapperRegex2

type WrapperRegex2 struct {
	*regexp2.Regexp
}

func (WrapperRegex2) Match

func (r WrapperRegex2) Match(content []byte) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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