Documentation
¶
Index ¶
- func AllTrue(bs ...bool) bool
- func AnyInList[T comparable]()
- func AnyTrue(bs ...bool) bool
- func ErrorOr(err error, val string) string
- func GetFieldList[T any, R any](items []T, fieldGetter func(T) R) []R
- func GetFieldMap[T any, K comparable](items []T, fieldGetter func(T) K) map[K]T
- func GetFieldMaps[T any, K comparable](items []T, fieldGetter func(T) K) map[K][]T
- func GetStructName(d any) string
- func InList[T comparable](item T, list ...T) bool
- func OneOf[T any](condition bool, result1 T, result2 T) T
- func OneOr[T any](result1 T, result2 T) T
- func RegexpCheck(pattern string, str string) bool
- func RegexpConvertSnake(s string) string
- func ReplaceMap(s string, replace map[string]string) (result string, err error)
- type DiffResp
- type LeaderPoller
- type LeaderPollerSetting
- type PollerImpl
- type PollerSetting
- type ReTry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllTrue ¶ added in v0.0.4
AllTrue AllTrue(true,true,true) == true AllTrue AllTrue(true,false,true) == false
func AnyInList ¶ added in v0.1.5
func AnyInList[T comparable]()
func AnyTrue ¶ added in v0.0.4
AnyTrue AnyTrue(true,false,false) == true AnyTrue AnyTrue(false,false,false) == false
func GetFieldList ¶ added in v0.1.2
GetFieldList is a generic function that takes a slice of items and a fieldGetter function, and returns a slice of any field type, such as string, int64, etc. examples
names1 := GetFieldList(items1, func(item Item) string { return item.Name }) // Retrieve the Age field list from items1 (int64 type)
func GetFieldMap ¶ added in v0.1.2
func GetFieldMap[T any, K comparable](items []T, fieldGetter func(T) K) map[K]T
func GetFieldMaps ¶ added in v0.1.2
func GetFieldMaps[T any, K comparable](items []T, fieldGetter func(T) K) map[K][]T
func GetStructName ¶ added in v0.0.7
func InList ¶ added in v0.0.4
func InList[T comparable](item T, list ...T) bool
InList InList["a",[]string{"a","b"}] == true
func RegexpCheck ¶ added in v0.1.6
RegexpCheck Use regular expressions to determine if a string matches Example: RegexpCheck(`(?i)^[a-zA-Z]+ (asc|desc)$`,`dafd Asc`) == true
func RegexpConvertSnake ¶ added in v0.1.7
RegexpConvertSnake convert string to snake case Example: RegexpConvertSnake(`AbC`) == `ab_c`
Types ¶
type DiffResp ¶ added in v0.1.1
type DiffResp[T comparable] struct { Added []T Deleted []T Same []T }
func Diff ¶ added in v0.1.1
func Diff[T comparable](olds, news []T) (resp DiffResp[T])
Diff The diff function is used to analyze the items to be added and deleted between two slices. example: var news = []string{`aa1`, `aa2`, `aa3`} var olds = []string{`aa1`, `aa4`} diffs := Diff(olds, news) result:added: aa2,aa3, deleted:aa4, same: aa1
type LeaderPoller ¶ added in v0.1.3
type LeaderPoller[T any] struct { // contains filtered or unexported fields }
func NewLeaderPoller ¶ added in v0.1.3
func NewLeaderPoller[T any](fs func(setting *LeaderPollerSetting)) *LeaderPoller[T]
func (*LeaderPoller[T]) Conditions ¶ added in v0.1.3
func (lp *LeaderPoller[T]) Conditions(conditionFunctions ...func() (T, error))
func (*LeaderPoller[T]) Run ¶ added in v0.1.3
func (lp *LeaderPoller[T]) Run(task func(T))
type LeaderPollerSetting ¶ added in v0.1.3
type PollerImpl ¶ added in v0.0.8
type PollerImpl[T any] struct { // contains filtered or unexported fields }
func Poller ¶ added in v0.0.8
func Poller[QueryResult any](query func(q *QueryResult) error) *PollerImpl[QueryResult]
func (*PollerImpl[T]) Catch ¶ added in v0.0.8
func (p *PollerImpl[T]) Catch(f func(err error))
func (*PollerImpl[T]) Setting ¶ added in v0.0.8
func (p *PollerImpl[T]) Setting(f func(settings *PollerSetting)) *PollerImpl[T]
func (*PollerImpl[T]) Stop ¶ added in v0.0.8
func (p *PollerImpl[T]) Stop()
func (*PollerImpl[T]) Then ¶ added in v0.0.8
func (p *PollerImpl[T]) Then(f func(result *T)) *PollerImpl[T]