utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package utils

Package utils

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T comparable](src []T, comparator func(element T) bool) bool

func Filter

func Filter[T comparable](src []T, filter func(element T) bool) (result []T)

func Find

func Find[T comparable](src []T, comparator func(element T) bool) T

func ForEach

func ForEach[T comparable](src []T, callback func(index int, element T))

func Map

func Map[T comparable](src []T, mapper func(element T) T)

func ReverseForEach

func ReverseForEach[T any](slice []T, f func(index int, value T))

func StrToFloat

func StrToFloat(str string, defaultValue float64) float64

StrToFloat cast string to float64

func StrToInt

func StrToInt(str string, defaultValue int) int

StrToInt cast string to int

Types

type Enum

type Enum[T comparable, V any] struct {
	Value T `json:"value"`
	Data  V `json:"data"`
}

Enum 枚举类型结构体,用于表示具有值和标签的枚举项 T 是可比较的类型

func NewEnum

func NewEnum[T comparable, V any](value T, data V) *Enum[T, V]

NewEnum 创建一个新的枚举实例

type EnumManager

type EnumManager[T comparable, V any] struct {
	// contains filtered or unexported fields
}

EnumManager 枚举管理器结构体,用于管理一组枚举项 T 是可比较的类型

func NewEnums

func NewEnums[T comparable, V any](enums ...*Enum[T, V]) *EnumManager[T, V]

func (*EnumManager[T, V]) GetEnum

func (manager *EnumManager[T, V]) GetEnum(value T) *Enum[T, V]

func (*EnumManager[T, V]) GetEnums

func (manager *EnumManager[T, V]) GetEnums() map[T]*Enum[T, V]

func (*EnumManager[T, V]) IsValidEnum

func (manager *EnumManager[T, V]) IsValidEnum(value T) bool

type IntervalActuator

type IntervalActuator struct {
	// contains filtered or unexported fields
}

func NewIntervalActuator

func NewIntervalActuator(interval time.Duration, callback func()) *IntervalActuator

func (*IntervalActuator) Start

func (h *IntervalActuator) Start()

func (*IntervalActuator) Stop

func (h *IntervalActuator) Stop()

type ManagerInterface

type ManagerInterface[T comparable, V any] interface {
	IsValidEnum(value T) bool
	GetEnum(value T) *Enum[T, V]
	GetEnums() map[T]*Enum[T, V]
}

ManagerInterface 枚举管理器接口,定义了枚举管理的基本操作 T 是可比较的类型

Jump to

Keyboard shortcuts

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