gookit/goutil Go 罕用的一些工具函数,数字,字符串,数组,Map,文件,谬误,工夫日期,非凡解决,格式化,罕用信息获取等等

工具包

  • arrutil array/slice 相干操作的函数工具包. 如:类型转换,元素查看等等
  • dump 简略的变量打印工具,打印 slice, map 会主动换行显示每个元素,同时会显示打印调用地位
  • cliutil CLI 的一些工具函数包. eg: read input, exec command, cmdline parse/build
  • errorx 为 go 提供加强的谬误实现,容许带有堆栈跟踪信息和包装另一个谬误。
  • envutil ENV 信息获取判断工具包. eg: get one, get info, parse var
  • fsutil 文件系统操作相干的工具函数包. eg: file and dir check, operate
  • maputil map 相干操作的函数工具包. eg: convert, sub-value get, simple merge
  • mathutil, numutil int/number 相干操作的函数工具包. eg: convert, math calc, random
  • netutil/httpreq 包装 http.Client 实现的更加易于应用的HTTP客户端
  • strutil string 相干操作的函数工具包. eg: bytes, check, convert, encode, format and more
  • sysutil system 相干操作的函数工具包. eg: sysenv, exec, user, process
  • testutil test help 相干操作的函数工具包. eg: http test, mock ENV value
  • timex 提供加强的 time.Time 实现。增加更多罕用的性能办法

    • 例如: DayStart(), DayAfter(), DayAgo(), DateFormat() 等等

Git 仓库

  • Github: https://github.com/gookit/goutil
  • Gitee: https://gitee.com/gookit/goutil

goutil/dump

goutil/dump - 是一个golang数据打印工具包,能够打印出丑陋易读的go slice, map, struct数据。

goutil/timex

goutil/timex 提供加强的 time.Time 实现。增加更多罕用的性能办法。例如: DayStart(), DayAfter(), DayAgo(), DateFormat() 等等

创立 timex 实例

now := timex.Now()// from time.Timetx := timex.New(time.Now())tx := timex.FromTime(time.Now())// from time unixtx := timex.FromUnix(1647411580)

从日期工夫字符串创立:

// auto match layout by datetimetx, err  := timex.FromString("2022-04-20 19:40:34")// custom set the datetime layouttx, err  := timex.FromString("2022-04-20 19:40:34", "2006-01-02 15:04:05")// use date template as layouttx, err  := timex.FromDate("2022-04-20 19:40:34", "Y-m-d H:I:S")

获取工夫:

tx := timex.Now()tx.Yesterday()tx.Tomorrow()tx.DayStart() // get time at Y-m-d 00:00:00tx.DayEnd() // get time at Y-m-d 23:59:59tx.HourStart() // get time at Y-m-d H:00:00tx.HourEnd() // get time at Y-m-d H:59:59tx.AddDay(2)tx.AddHour(1)tx.AddMinutes(15)tx.AddSeconds(120)

格式化工夫:

tx.DateFormat("y/m/d H:I")date := tx.DateFormat("Y-m-d H:I:S") // Output: 2022-04-20 19:40:34date = tx.DateFormat("y-m-d H:I:S") // Output: 22-04-20 19:40:34

更多工具包

更多工具和应用请查看 README https://github.com/gookit/gou...