gookit/goutil - Go 一些常用的工具函数收集、整理实现 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
jxia
V2EX    Go 编程语言

gookit/goutil - Go 一些常用的工具函数收集、整理实现

  •  1
     
  •   jxia 2022-06-09 13:27:25 +08:00 1968 次点击
    这是一个创建于 1225 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 Repo:

    goutil/dump

    goutil/dump - 是一个 golang 数据打印工具包,可以打印出漂亮易读的 go slice, map, struct 数据。

    struct

    goutil/timex

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

    创建 timex 实例

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

    从日期时间字符串创建:

    // auto match layout by datetime tx, err := timex.FromString("2022-04-20 19:40:34") // custom set the datetime layout tx, err := timex.FromString("2022-04-20 19:40:34", "2006-01-02 15:04:05") // use date template as layout tx, 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:00 tx.DayEnd() // get time at Y-M-D 23:59:59 tx.HourStart() // get time at Y-M-D H:00:00 tx.HourEnd() // get time at Y-M-D H:59:59 tx.AddDay(2) tx.AddHour(1) tx.AddMinutes(15) tx.AddSeconds(120) 

    更多

    更多工具和使用请查看 README https://github.com/gookit/goutil/blob/master/README.zh-CN.md

    3 条回复    2022-06-11 09:45:43 +08:00
    hailaz
        1
    hailaz  
       2022-06-10 10:30:32 +08:00
    https://github.com/gogf/gf
    有个差不多的
    jxia
        2
    jxia  
    OP
       2022-06-10 20:55:07 +08:00
    @hailaz gf 这是个开发框架啊
    349865361
        3
    349865361  
       2022-06-11 09:45:43 +08:00
    这个库刚开始搞 go 就发现在用了 已经用了 3 个月了
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3523 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 10:32 PVG 18:32 LAX 03:32 JFK 06:32
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86