Documentation
¶
Index ¶
- func ConvertModel(srcModel any, dstModelPointer any) error
- func FileExists(path string) (bool, error)
- func Float2String(f float64, suffix string) string
- func GroupSort[T any](src []T, getGroupKey func(T) string, sortGroup func([]T, []T) bool, ...) []T
- func InitTimezone()
- func Int2String(i int, suffix string) string
- func LoopExecute(ctx context.Context, job func() error, interval time.Duration) error
- func Map2Struct(srcMap map[string]any, dstStructPointer interface{}) error
- func StrTerminalLen(str string) int
- func TableStr(lines [][]string, colMaxWidth []int) string
- func TextBlue(src string) string
- func TextGreen(src string) string
- func TextPurple(src string) string
- func TextRed(src string) string
- func TextYellow(src string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertModel ¶
ConvertModel 源模型的字段会覆盖目标模型的字段。注意转换多个源到目的模型时多个源的字段相同问题。
func FileExists ¶
FileExists 检查指定路径的文件是否存在 参数:
path - 要检查的文件路径
返回值:
bool - 文件存在返回true,否则false error - 底层系统调用返回的错误(当错误不是文件不存在时)
func Float2String ¶
func GroupSort ¶
func GroupSort[T any](src []T, getGroupKey func(T) string, sortGroup func([]T, []T) bool, sortMember func(T, T) bool) []T
GroupSort 对切片进行分组排序处理,没必要排序的元素会保持原顺序 参数:
src - 需要处理的源切片 getGroupKey - 获取元素分组键的函数,返回字符串类型的分组标识 sortGroup - 组间排序函数,参数是两个组的元素切片,返回true表示第一个组应排在第二个组前,为nil时不排序 sortMember - 组内排序函数,用于对同一组的元素进行排序,返回true表示第一个元素应排在第二个元素前,为nil时不排序
返回值:
[]T - 返回按分组排序后的新切片
注意:
排序函数返回false都会触发元素更换位置,也就是大小比较用好等于号 sortGroup有2个slice传进来,它们的长度>=1
func InitTimezone ¶
func InitTimezone()
func Int2String ¶
func LoopExecute ¶
LoopExecute 2次逻辑执行相隔的时间为:逻辑的执行时间 + 间隔时间
func Map2Struct ¶
Map2Struct 对于结构体字段名,若map中有就拿过来覆盖。 对于嵌套结构体的问题:调用方传入嵌套的字段。
func StrTerminalLen ¶
StrTerminalLen 获取字符串在终端中输出的长度 例子: 中文 => 4 en => 2
func TextPurple ¶
func TextYellow ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.