diff --git a/README.md b/README.md index 3d1fcc5..ca233d1 100644 --- a/README.md +++ b/README.md @@ -128,16 +128,22 @@ import "github.com/duke-git/lancet/v2/compare" - **Equal** : Checks if two values are equal or not. (check both type and value) [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare.md#Equal)] + [[play](https://go.dev/play/p/wmVxR-to4lz)] - **EqualValue** : Checks if two values are equal or not. (check value only) [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare.md#EqualValue)] + [[play](https://go.dev/play/p/fxnna_LLD9u)] - **LessThan** : Checks if value `left` less than value `right`. [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare.md#LessThan)] + [[play](https://go.dev/play/p/cYh7FQQj0ne)] - **GreaterThan** : Checks if value `left` greater than value `right`. [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare.md#GreaterThan)] + [[play](https://go.dev/play/p/9-NYDFZmIMp)] - **LessOrEqual** : Checks if value `left` less than or equal than value `right`. [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare.md#LessOrEqual)] + [[play](https://go.dev/play/p/e4T_scwoQzp)] - **GreaterOrEqual** : Checks if value `left` less greater or equal than value `right`. [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare.md#GreaterOrEqual)] + [[play](https://go.dev/play/p/vx8mP0U8DFk)] ### 3. Concurrency package contain some functions to support concurrent programming. eg, goroutine, channel, async. @@ -581,7 +587,6 @@ import "github.com/duke-git/lancet/v2/fileutil" [[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#ReadCsvFile)] [[play](https://go.dev/play/p/OExTkhGEd3_u)] - ### 10. Formatter contains some functions for data formatting. ```go @@ -1341,7 +1346,6 @@ import "github.com/duke-git/lancet/v2/strutil" [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#IndexOffset)] [[play](https://go.dev/play/p/qZo4lV2fomB)] - ### 21. System package contain some functions about os, runtime, shell command. ```go diff --git a/README_zh-CN.md b/README_zh-CN.md index 4c2d6cf..95fbc57 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -127,16 +127,22 @@ import "github.com/duke-git/lancet/v2/compare" - **Equal** : 检查两个值是否相等(检查类型和值)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare_zh-CN.md#Equal)] + [[play](https://go.dev/play/p/wmVxR-to4lz)] - **EqualValue** : 检查两个值是否相等(只检查值)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare_zh-CN.md#EqualValue)] + [[play](https://go.dev/play/p/fxnna_LLD9u)] - **LessThan** : 验证参数`left`的值是否小于参数`right`的值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare_zh-CN.md#LessThan)] + [[play](https://go.dev/play/p/cYh7FQQj0ne)] - **GreaterThan** : 验证参数`left`的值是否大于参数`right`的值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare_zh-CN.md#GreaterThan)] + [[play](https://go.dev/play/p/9-NYDFZmIMp)] - **LessOrEqual** : 验证参数`left`的值是否小于或等于参数`right`的值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare_zh-CN.md#LessOrEqual)] + [[play](https://go.dev/play/p/e4T_scwoQzp)] - **GreaterOrEqual** : 验证参数`left`的值是否大于或等于参数`right`的值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/compare_zh-CN.md#GreaterOrEqual)] + [[play](https://go.dev/play/p/vx8mP0U8DFk)] ### 3. concurrency 包含一些支持并发编程的功能。例如:goroutine, channel, async 等。 @@ -564,7 +570,7 @@ import "github.com/duke-git/lancet/v2/fileutil" - **CurrentPath** : 返回当前位置的绝对路径。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#CurrentPath)] [[play](https://go.dev/play/p/s74a9iBGcSw)] -- **IsZipFile** : 判断文件是否是zip压缩文件。 +- **IsZipFile** : 判断文件是否是 zip 压缩文件。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#IsZipFile)] [[play](https://go.dev/play/p/9M0g2j_uF_e)] - **FileSize** : 返回文件字节大小。 @@ -573,14 +579,13 @@ import "github.com/duke-git/lancet/v2/fileutil" - **MTime** : 返回文件修改时间(unix timestamp)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#MTime)] [[play](https://go.dev/play/p/s_Tl7lZoAaY)] -- **Sha** : 返回文件sha值。 +- **Sha** : 返回文件 sha 值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#Sha)] [[play](https://go.dev/play/p/VfEEcO2MJYf)] -- **ReadCsvFile** : 读取csv文件内容到切片。 +- **ReadCsvFile** : 读取 csv 文件内容到切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#ReadCsvFile)] [[play](https://go.dev/play/p/OExTkhGEd3_u)] - ### 10. formatter 格式化器包含一些数据格式化处理方法。 ```go @@ -842,16 +847,16 @@ import "github.com/duke-git/lancet/v2/netutil" [[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#HttpPut)] - **HttpPatchdeprecated** : 发送 http patch 请求(已弃用:SendRequest 代替)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#HttpPatch)] -- **ParseHttpResponse** : 解析http响应体到目标结构体。 +- **ParseHttpResponse** : 解析 http 响应体到目标结构体。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#ParseHttpResponse)] -- **DownloadFile** : 从指定的server地址下载文件。 +- **DownloadFile** : 从指定的 server 地址下载文件。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#DownloadFile)] -- **UploadFile** : 将文件上传指定的server地址。 +- **UploadFile** : 将文件上传指定的 server 地址。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#UploadFile)] -- **IsPingConnected** : 检查能否ping通主机。 +- **IsPingConnected** : 检查能否 ping 通主机。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#IsPingConnected)] [[play](https://go.dev/play/p/q8OzTijsA87)] -- **IsTelnetConnected** : 检查能否telnet到主机。 +- **IsTelnetConnected** : 检查能否 telnet 到主机。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#IsTelnetConnected)] [[play](https://go.dev/play/p/yiLCGtQv_ZG)] @@ -995,7 +1000,7 @@ import "github.com/duke-git/lancet/v2/slice" - **FindLastdeprecated** : 从头到尾遍历 slice 的元素,返回最后一个通过 predicate 函数真值测试的元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindLast)] [[play](https://go.dev/play/p/FFDPV_j7URd)] -- **FindLastBy** : 从遍历slice的元素,返回最后一个通过predicate函数真值测试的元素。 +- **FindLastBy** : 从遍历 slice 的元素,返回最后一个通过 predicate 函数真值测试的元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindLastBy)] [[play](https://go.dev/play/p/8iqomzyCl_s)] - **Flatten** : 将多维切片展平一层。 @@ -1339,7 +1344,7 @@ import "github.com/duke-git/lancet/v2/strutil" - **HasSuffixAny** : 检查字符串是否以指定字符串数组中的任何一个结尾。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#HasSuffixAny)] [[play](https://go.dev/play/p/sKWpCQdOVkx)] -- **IndexOffset** : 将字符串偏移idxFrom后,返回字符串中第一个 substr 实例的索引。 +- **IndexOffset** : 将字符串偏移 idxFrom 后,返回字符串中第一个 substr 实例的索引。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#IndexOffset)] [[play](https://go.dev/play/p/qZo4lV2fomB)] diff --git a/compare/compare.go b/compare/compare.go index c5197e4..56c5fda 100644 --- a/compare/compare.go +++ b/compare/compare.go @@ -27,32 +27,38 @@ var ( ) // Equal checks if two values are equal or not. (check both type and value) +// Play: https://go.dev/play/p/wmVxR-to4lz func Equal(left, right any) bool { return compareValue(equal, left, right) } // EqualValue checks if two values are equal or not. (check value only) +// Play: https://go.dev/play/p/fxnna_LLD9u func EqualValue(left, right any) bool { ls, rs := convertor.ToString(left), convertor.ToString(right) return ls == rs } // LessThan checks if value `left` less than value `right`. +// Play: https://go.dev/play/p/cYh7FQQj0ne func LessThan(left, right any) bool { return compareValue(lessThan, left, right) } // GreaterThan checks if value `left` greater than value `right`. +// Play: https://go.dev/play/p/9-NYDFZmIMp func GreaterThan(left, right any) bool { return compareValue(greaterThan, left, right) } // LessOrEqual checks if value `left` less than or equal to value `right`. +// Play: https://go.dev/play/p/e4T_scwoQzp func LessOrEqual(left, right any) bool { return compareValue(lessOrEqual, left, right) } // GreaterOrEqual checks if value `left` greater than or equal to value `right`. +// Play: https://go.dev/play/p/vx8mP0U8DFk func GreaterOrEqual(left, right any) bool { return compareValue(greaterOrEqual, left, right) }