Documentation
¶
Index ¶
- Constants
- func AtomicWriteSmallFile(file string, content []byte, perm os.FileMode) error
- func BytesToFloat32(b []byte, order binary.ByteOrder) float32
- func ConvertModel(srcModel any, dstModelPointer any) error
- func CutRightZeroBytes(b []byte) []byte
- func DateOnlyInt2Time(dateInt int) time.Time
- func FileExists(path string) (bool, error)
- func Float2String(f float64, suffix string) string
- func Float32ToBytes(f float32, order binary.ByteOrder) []byte
- func Float64Invalid(f float64) bool
- func GBKToUTF8(gbk []byte) ([]byte, error)
- func GenRandomMil(maxMill int64) time.Duration
- func GroupSort[T any](src []T, getGroupKey func(T) string, sortGroup func([]T, []T) bool, ...) []T
- func HasPrefixs(str string, prefixs []string) bool
- func HasSuffixs(str string, suffixs []string) bool
- func HtmlGB180302UTF8(body io.ReadCloser) io.Reader
- func HtmlGBK2UTF8(body io.ReadCloser) io.Reader
- func HtmlWindows12522UTF8(body io.ReadCloser) io.Reader
- func HttpGetContent(fullUrl string, headers map[string]string, params map[string]string) ([]byte, error)
- func HttpGetHtml(fullUrl string, headers map[string]string, params map[string]string, ...) (string, error)
- func HttpPost(fullUrl string, headers map[string]string, formDatas map[string]string) ([]byte, error)
- func InitTimezone()
- func Int2String(i int, suffix string) string
- func IsIPv4(s string) bool
- func LoadFromCache[T any](cacheFile string) (T, error)
- func LoadFromCsv(csvFile string) ([][]string, error)
- func LoopExecute(ctx context.Context, job func() error, prepare time.Duration, ...) error
- func Map2Struct(srcMap map[string]any, dstStructPointer any) error
- func NewPrintCharPositionDiff() *printDiff
- func RemoveAllZeroBytes(b []byte) []byte
- func SaveToCache[T any](data T, cacheFile string) error
- func SaveToCsv(data [][]string, csvFile string, readOnly bool) error
- func StrTerminalLen(str string) int
- func SyncAtomicWriteSmallFile(file string, content []byte, perm os.FileMode) error
- 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
- func TrimZeroBytes(b []byte) []byte
- func TryDo(ctx context.Context, job func() (bool, error), maxTimes int) error
- func UTF8ToGBK(utf8 []byte) ([]byte, error)
Constants ¶
const ( // 避免不关注年的时间变量出现分钟的差错 // 1901年前使用LMT(分钟会有误差),1928年后国际天文学会正式确立时区标准UTC,1949年后新中国时区统一CST NotLMTYear = 1928 )
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteSmallFile ¶
异步写文件。写完文件并关闭后,若在操作系统同步文件前断电,会丢失文件。
func ConvertModel ¶
ConvertModel 源模型的字段会覆盖目标模型的字段。注意转换多个源到目的模型时多个源的字段相同问题。
func CutRightZeroBytes ¶
CutRightZeroBytes 一旦发现0x00值,立即切掉后面所有数据
func DateOnlyInt2Time ¶
输入数字:20250101 输出:time.Time 性能比数字转字符串再转time.Time快很多
func FileExists ¶
FileExists 检查指定路径的文件是否存在 参数:
path - 要检查的文件路径
返回值:
bool - 文件存在返回true,否则false error - 底层系统调用返回的错误(当错误不是文件不存在时)
func Float2String ¶
func GenRandomMil ¶
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 HasPrefixs ¶
func HasSuffixs ¶
func HtmlGB180302UTF8 ¶
func HtmlGB180302UTF8(body io.ReadCloser) io.Reader
func HtmlGBK2UTF8 ¶
func HtmlGBK2UTF8(body io.ReadCloser) io.Reader
func HtmlWindows12522UTF8 ¶
func HtmlWindows12522UTF8(body io.ReadCloser) io.Reader
func HttpGetContent ¶
func HttpGetContent(fullUrl string, headers map[string]string, params map[string]string) ([]byte, error)
HttpGetContent 提供获取http内容的能力
func HttpGetHtml ¶
func HttpGetHtml(fullUrl string, headers map[string]string, params map[string]string, coder func(body io.ReadCloser) io.Reader) (string, error)
HttpGetHtml 提供获取html的能力
func HttpPost ¶
func HttpPost(fullUrl string, headers map[string]string, formDatas map[string]string) ([]byte, error)
HttpPost 提供post请求的能力
func Int2String ¶
func LoadFromCsv ¶
func LoopExecute ¶
func LoopExecute(ctx context.Context, job func() error, prepare time.Duration, interval time.Duration) error
LoopExecute 2次逻辑执行相隔的时间为:逻辑的执行时间 + 间隔时间
func Map2Struct ¶
Map2Struct 对于结构体字段名,若map中有就拿过来覆盖。 对于嵌套结构体的问题:调用方传入嵌套的字段。
func NewPrintCharPositionDiff ¶
func NewPrintCharPositionDiff() *printDiff
func RemoveAllZeroBytes ¶
RemoveAllZeroBytes 移除字节切片中的所有0x00值
func SaveToCache ¶
func StrTerminalLen ¶
StrTerminalLen 获取字符串在终端中输出的长度 例子: 中文 => 4 en => 2
func SyncAtomicWriteSmallFile ¶
同步写文件。写完文件后,让操作系统同步文件,然后再关闭文件,避免文件的丢失。 同步操作会损耗性能
func TableStr ¶
TableStr 获取可以展示表格的字符串 将多个line[]string,加入lines[][]string中 当 colMaxWidth 为nil,花费时间来自动计算
func TextPurple ¶
func TextYellow ¶
Types ¶
This section is empty.