util

package module
v0.0.0-...-88048df Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

README

util

import

go get github.com/13inary/util

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertModel

func ConvertModel(srcModel any, dstModelPointer any) error

ConvertModel 源模型的字段会覆盖目标模型的字段。注意转换多个源到目的模型时多个源的字段相同问题。

func FileExists

func FileExists(path string) (bool, error)

FileExists 检查指定路径的文件是否存在 参数:

path - 要检查的文件路径

返回值:

bool - 文件存在返回true,否则false
error - 底层系统调用返回的错误(当错误不是文件不存在时)

func Float2String

func Float2String(f float64, suffix string) string

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 Int2String(i int, suffix string) string

func LoopExecute

func LoopExecute(ctx context.Context, job func() error, interval time.Duration) error

LoopExecute 2次逻辑执行相隔的时间为:逻辑的执行时间 + 间隔时间

func Map2Struct

func Map2Struct(srcMap map[string]any, dstStructPointer interface{}) error

Map2Struct 对于结构体字段名,若map中有就拿过来覆盖。 对于嵌套结构体的问题:调用方传入嵌套的字段。

func StrTerminalLen

func StrTerminalLen(str string) int

StrTerminalLen 获取字符串在终端中输出的长度 例子: 中文 => 4 en => 2

func TableStr

func TableStr(lines [][]string, colMaxWidth []int) string

TableStr 获取可以展示表格的字符串 当 colMaxWidth 为nil,花费时间来自动计算

func TextBlue

func TextBlue(src string) string

func TextGreen

func TextGreen(src string) string

func TextPurple

func TextPurple(src string) string

func TextRed

func TextRed(src string) string

func TextYellow

func TextYellow(src string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳