From 8469c346ccde852b519121a3a56c9c76705d47e4 Mon Sep 17 00:00:00 2001 From: Inhere Date: Fri, 16 Jun 2023 11:44:01 +0800 Subject: [PATCH] :necktie: up: comdef,str - add some commonly interface and update str, doc logic --- comdef/comdef.go | 13 +++++++++++++ internal/gendoc/main.go | 1 + internal/template/README.md.tpl | 11 +++++++---- internal/template/README.zh-CN.md.tpl | 9 ++++++--- strutil/filter.go | 5 ++++- strutil/id.go | 3 ++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/comdef/comdef.go b/comdef/comdef.go index 2a3f7ef96..06e86a2a4 100644 --- a/comdef/comdef.go +++ b/comdef/comdef.go @@ -20,6 +20,19 @@ type StringWriteStringer interface { fmt.Stringer } +// StringMatcher interface +type StringMatcher interface { + Match(s string) bool +} + +// StringMatchFunc definition +type StringMatchFunc func(s string) bool + +// Match satisfies the StringMatcher interface +func (fn StringMatchFunc) Match(s string) bool { + return fn(s) +} + type ( // MarshalFunc define MarshalFunc func(v any) ([]byte, error) diff --git a/internal/gendoc/main.go b/internal/gendoc/main.go index d18d832a5..62d6b040b 100644 --- a/internal/gendoc/main.go +++ b/internal/gendoc/main.go @@ -22,6 +22,7 @@ import ( var ( hidden = []string{ + "basefn", "netutil", "comdef", "internal", diff --git a/internal/template/README.md.tpl b/internal/template/README.md.tpl index 9abbb79f0..72e21285e 100644 --- a/internal/template/README.md.tpl +++ b/internal/template/README.md.tpl @@ -18,7 +18,7 @@ - [`envutil`](./envutil) ENV util for current runtime env information. eg: get one, get info, parse var - [`fmtutil`](./fmtutil) Format data util functions. eg: data, size, time - [`fsutil`](./fsutil) Filesystem util functions, quick create, read and write file. eg: file and dir check, operate -- [`jsonutil`](./jsonutil) some util functions for quick read, write, encode, decode JSON data. +- [`jsonutil`](./jsonutil) Provide some util functions for quick read, write, encode, decode JSON data. - [`maputil`](./maputil) Map data util functions. eg: convert, sub-value get, simple merge - [`mathutil`](./mathutil) Math(int, number) util functions. eg: convert, math calc, random - `netutil` Network util functions @@ -35,16 +35,19 @@ - [cmdline](./cliutil/cmdline) Provide cmdline parse, args build to cmdline - [`dump`](./dump): GO value printing tool. print slice, map will auto wrap each element and display the call location - [`errorx`](./errorx) Provide an enhanced error implements for go, allow with stacktrace and wrap another error. +- [`finder`](./fsutil/finder) Provides a simple and convenient filedir lookup function, supports filtering, excluding, matching, ignoring, etc. - net util: - [httpreq](netutil/httpreq) An easier-to-use HTTP client that wraps http.Client - string util: - [textscan](strutil/textscan) Implemented a parser that quickly scans and analyzes text content. It can be used to parse INI, Properties and other formats -- sys util: + - [textutil](strutil/textutil) Provide some extensions text handle util functions. eg: text replace, etc. +- system util: - [clipboard](./sysutil/clipboard) Provide a simple clipboard read and write operations. - [cmdr](./sysutil/cmdr) Provide for quick build and run a cmd, batch run multi cmd tasks - [process](./sysutil/process) Provide some process handle util functions. -- [`testutil`](./testutil) Test help util functions. eg: http test, mock ENV value - - [assert](./testutil/assert) Asserts functions for help testing +- [`testutil`](testutil) Test help util functions. eg: http test, mock ENV value + - [assert](testutil/assert) Provides commonly asserts functions for help testing + - [fakeobj](testutil/fakeobj) provides a fake object for testing. such as fake fs.File, fs.FileInfo, fs.DirEntry etc. - [`timex`](./timex) Provides an enhanced time.Time implementation. Add more commonly used functional methods - such as: DayStart(), DayAfter(), DayAgo(), DateFormat() and more. diff --git a/internal/template/README.zh-CN.md.tpl b/internal/template/README.zh-CN.md.tpl index 06aca5c04..74e453e56 100644 --- a/internal/template/README.zh-CN.md.tpl +++ b/internal/template/README.zh-CN.md.tpl @@ -33,16 +33,19 @@ - [`cflag`](./cflag): 包装和扩展 go `flag.FlagSet` 以方便快速的构建简单的命令行应用程序 - [`dump`](./dump) GO变量打印工具,打印 slice, map 会自动换行显示每个元素,同时会显示打印调用位置 - [`errorx`](./errorx) 为 go 提供增强的错误实现,允许带有堆栈跟踪信息和包装另一个错误。 -- strutil: +- [`finder`](./fsutil/finder) 提供简单方便的file/dir查找功能,支持过滤、排除、匹配、忽略等。 +- netutil: - `netutil/httpreq` 包装 http.Client 实现的更加易于使用的HTTP客户端 - strutil: - [textscan](strutil/textscan) 实现了一个快速扫描和分析文本内容的解析器. 可用于解析 INI, Properties 等格式内容 + - [textutil](strutil/textutil) 提供一些常用的扩展文本处理功能函数。 - sysutil: - [clipboard](sysutil/clipboard) 提供简单的剪贴板读写操作工具库 - [cmdr](sysutil/cmdr) 提供快速构建和运行一个cmd,批量运行多个cmd任务 - - [process](./sysutil/process) 提供一些进程操作相关的实用功能。 + - [process](sysutil/process) 提供一些进程操作相关的实用功能。 - [`testutil`](testutil) test help 相关操作的函数工具包. eg: http test, mock ENV value - - [assert](testutil/assert) 用于帮助测试的断言函数工具包 + - [assert](testutil/assert) 用于帮助测试的断言函数工具包,方便编写单元测试。 + - [fakeobj](testutil/fakeobj) 提供一些接口的假的实现,用于模拟测试. 例如 fs.File, fs.FileInfo, fs.DirEntry 等等. - [`timex`](timex) 提供增强的 time.Time 实现。添加更多常用的功能方法 - 提供类似 `Y-m-d H:i:s` 的日期时间格式解析处理 - 例如: DayStart(), DayAfter(), DayAgo(), DateFormat() 等等 diff --git a/strutil/filter.go b/strutil/filter.go index c80f6643a..f925a4449 100644 --- a/strutil/filter.go +++ b/strutil/filter.go @@ -64,6 +64,9 @@ func FilterEmail(s string) string { return s } - // According to rfc5321, "The local-part of a mailbox MUST BE treated as case sensitive" + // According to rfc5321, "The local-part of a mailbox MUST BE treated as case-sensitive" return s[0:i] + "@" + strings.ToLower(s[i+1:]) } + +// func Filter(ss []string, fls ...comdef.StringMatchFunc) []string { +// } diff --git a/strutil/id.go b/strutil/id.go index 028264916..0e8fe6526 100644 --- a/strutil/id.go +++ b/strutil/id.go @@ -39,7 +39,8 @@ func MicroTimeHexID() string { // DatetimeNo generate. can use for order-no. // -// No prefix, return like: 2023041410484904074285478388(len: 28) +// - No prefix, return like: 2023041410484904074285478388(len: 28) +// - With prefix, return like: prefix2023041410484904074285478388(len: 28 + len(prefix)) func DatetimeNo(prefix string) string { nt := time.Now() pl := len(prefix)