diff --git a/README.md b/README.md index 9699630..a67c772 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,30 @@ import "github.com/duke-git/lancet/v2/concurrency" - **Tee** : split one chanel into two channels, until cancel the context. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#Tee)] [[play](https://go.dev/play/p/3TQPKnCirrP)] +- **NewKeyedLocker** : KeyedLocker is a simple implementation of a keyed locker that allows for non-blocking lock acquisition. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#NewKeyedLocker)] + [[play](https://go.dev/play/p/todo)] +- **Do** :acquires a lock for the specified key and executes the provided function. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#Do)] + [[play](https://go.dev/play/p/todo)] +- **NewRWKeyedLocker** :RRWKeyedLocker is a read-write version of KeyedLocker. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#NewRWKeyedLocker)] + [[play](https://go.dev/play/p/todo)] +- **RLock** : acquires a read lock for the specified key and executes the provided function. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#RLock)] + [[play](https://go.dev/play/p/todo)] +- **Lock** : acquires a write lock for the specified key and executes the provided function. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#Lock)] + [[play](https://go.dev/play/p/todo)] +- **NewTryKeyedLocker** : TryKeyedLocker is a non-blocking version of KeyedLocker. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#NewTryKeyedLocker)] + [[play](https://go.dev/play/p/todo)] +- **TryLock** : TryLock tries to acquire a lock for the specified key. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#TryLock)] + [[play](https://go.dev/play/p/todo)] +- **Unlock** : Unlock releases the lock for the specified key. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/concurrency.md#Unlock)] + [[play](https://go.dev/play/p/todo)]

4. Condition package contains some functions for conditional judgment. eg. And, Or, TernaryOperator...       index

@@ -331,7 +355,7 @@ import "github.com/duke-git/lancet/v2/convertor" - **ToRawUrlBase64** : converts a value to a string encoded in raw url Base64. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToRawUrlBase64)] [[play](https://go.dev/play/p/HwdDPFcza1O)] -- **ToBigInt** : converts an integer of any supported type (int, int64, uint64, etc.) to *big.Int. +- **ToBigInt** : converts an integer of any supported type (int, int64, uint64, etc.) to \*big.Int. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToBigInt)] [[play](https://go.dev/play/p/X3itkCxwB_x)] @@ -693,7 +717,6 @@ import optional "github.com/duke-git/lancet/v2/datastructure/optional" [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datastructure/hashmap.md)] - **Optional** : Optional container. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datastructure/optional.md)] -

9. EventBus is an event bus used for handling events within an application.        Index

@@ -778,6 +801,9 @@ import "github.com/duke-git/lancet/v2/fileutil" - **RemoveFile** : remove file, param should be file path. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#RemoveFile)] [[play](https://go.dev/play/p/P2y0XW8a1SH)] +- **RemoveDir** : delete directory. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#RemoveDir)] + [[play](https://go.dev/play/p/todo)] - **ReadFileToString** : return string of file content. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#ReadFileToString)] [[play](https://go.dev/play/p/cmfwp_5SQTp)] @@ -926,7 +952,6 @@ import "github.com/duke-git/lancet/v2/function" [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/function.md#Watcher)] [[play](https://go.dev/play/p/l2yrOpCLd1I)] -

12. Maputil package includes some functions to manipulate map.       index

```go @@ -1097,7 +1122,9 @@ import "github.com/duke-git/lancet/v2/maputil" - **GetOrDefault** : returns the value of the given key or a default value if the key is not present. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/maputil.md#GetOrDefault)] [[play](https://go.dev/play/p/99QjSYSBdiM)] - +- **FindValuesBy** : returns a slice of values from the map that satisfy the given predicate function. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/maputil.md#FindValuesBy)] + [[play](https://go.dev/play/p/todo)]

13. Mathutil package implements some functions for math calculation.        index

@@ -1282,6 +1309,12 @@ import "github.com/duke-git/lancet/v2/netutil" - **IsTelnetConnected** : checks if can if can telnet the specified host or not. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/netutil.md#IsTelnetConnected)] [[play](https://go.dev/play/p/yiLCGtQv_ZG)] +- **BuildUrl** : builds a URL from the given params. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/netutil.md#BuildUrl)] + [[play](https://go.dev/play/p/todo)] +- **AddQueryParams** : adds query parameters to the given URL. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/netutil.md#AddQueryParams)] + [[play](https://go.dev/play/p/todo)]

15. Pointer package contains some util functions to operate go pointer.        index

@@ -1407,7 +1440,6 @@ import "github.com/duke-git/lancet/v2/retry" - **RetryWithExponentialWithJitterBackoff** : set exponential strategy backoff. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/retry.md#RetryWithExponentialWithJitterBackoff)] [[play](https://go.dev/play/p/xp1avQmn16X)] -

18. Slice contains some functions to manipulate slice.        index

@@ -1654,7 +1686,7 @@ import "github.com/duke-git/lancet/v2/slice" - **Partition** : partition all slice elements with the evaluation of the given predicate functions. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Partition)] [[play](https://go.dev/play/p/lkQ3Ri2NQhV)] -- **Random** : get a random item of slice, return its index, when slice is empty, return -1. +- **Random** : get a random item of slice, return its index, when slice is empty, return -1. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Random)] [[play](https://go.dev/play/p/UzpGQptWppw)] - **SetToDefaultIf** : set elements to their default value if they match the given predicate. @@ -2012,7 +2044,6 @@ import "github.com/duke-git/lancet/v2/system" [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/system.md#GetProcessInfo)] [[play](https://go.dev/play/p/NQDVywEYYx7)] -

23. Tuple package implements tuple data type and some operations on it.        index

```go @@ -2195,6 +2226,9 @@ import "github.com/duke-git/lancet/v2/validator" - **IsNumberStr** : check if the string can convert to a number. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsNumberStr)] [[play](https://go.dev/play/p/LzaKocSV79u)] +- **IsAlphaNumeric** : check if the string is alphanumeric. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsAlphaNumeric)] + [[play](https://go.dev/play/p/todo)] - **IsJSON** : check if the string is valid JSON. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsJSON)] [[play](https://go.dev/play/p/8Kip1Itjiil)] @@ -2315,7 +2349,7 @@ import "github.com/duke-git/lancet/v2/xerror" - **TryUnwrap** : check if err is nil then it returns a valid value. If err is not nil, TryUnwrap panics with err. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/xerror.md#TryUnwrap)] [[play](https://go.dev/play/p/acyZVkNZEeW)] -- **TryCatch** : simple simulation of Java-style try-catch. +- **TryCatch** : simple simulation of Java-style try-catch. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/xerror.md#TryCatch)] [[play](https://go.dev/play/p/D5Mdb0mRj0P)] @@ -2324,6 +2358,7 @@ import "github.com/duke-git/lancet/v2/xerror" #### [Contribution Guide](./CONTRIBUTION.md) ## Contributors + Thank you to all the people who contributed to lancet! diff --git a/README_zh-CN.md b/README_zh-CN.md index fbc72ab..a3ea447 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -101,7 +101,6 @@ func main() { - [Validator](#user-content-validator) - [Xerror](#user-content-xerror) -

1. algorithm 包实现一些基本查找和排序算法。        回到目录

```go @@ -214,6 +213,30 @@ import "github.com/duke-git/lancet/v2/concurrency" - **Tee** : 将一个 channel 分成两个 channel,直到取消上下文。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#Tee)] [[play](https://go.dev/play/p/3TQPKnCirrP)] +- **NewKeyedLocker** : NewKeyedLocker 创建一个新的 KeyedLocker,并为锁的过期设置指定的 TTL。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#NewKeyedLocker)] + [[play](https://go.dev/play/p/todo)] +- **Do** :为指定的键获取锁并执行提供的函数。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#Do)] + [[play](https://go.dev/play/p/todo)] +- **NewRWKeyedLocker** :RWKeyedLocker 是一个简单的键值读写锁实现,允许非阻塞的锁获取。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#NewRWKeyedLocker)] + [[play](https://go.dev/play/p/todo)] +- **RLock** : 为指定的键获取读锁并执行提供的函数。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#RLock)] + [[play](https://go.dev/play/p/todo)] +- **Lock** : 为指定的键获取锁并执行提供的函数。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#Lock)] + [[play](https://go.dev/play/p/todo)] +- **NewTryKeyedLocker** : 创建一个 TryKeyedLocker 实例,TryKeyedLocker 是 KeyedLocker 的非阻塞版本。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#NewTryKeyedLocker)] + [[play](https://go.dev/play/p/todo)] +- **TryLock** : TryLock 尝试获取指定键的锁。如果锁成功获取,则返回 true,否则返回 false。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#TryLock)] + [[play](https://go.dev/play/p/todo)] +- **Unlock** : 释放指定键的锁。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/concurrency.md#Unlock)] + [[play](https://go.dev/play/p/todo)]

4. condition 包含一些用于条件判断的函数。       回到目录

@@ -319,19 +342,19 @@ import "github.com/duke-git/lancet/v2/convertor" - **GbkToUtf8** : GBK 编码转 utf8 编码。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#GbkToUtf8)] [[play](https://go.dev/play/p/OphmHCN_9u8)] -- **ToStdBase64** : 将值转换为StdBase64编码的字符串。 +- **ToStdBase64** : 将值转换为 StdBase64 编码的字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToStdBase64)] [[play](https://go.dev/play/p/_fLJqJD3NMo)] -- **ToUrlBase64** : 将值转换为url Base64编码的字符串。 +- **ToUrlBase64** : 将值转换为 url Base64 编码的字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToUrlBase64)] [[play](https://go.dev/play/p/C_d0GlvEeUR)] -- **ToRawStdBase64** : 将值转换为RawStdBase64编码的字符串。 +- **ToRawStdBase64** : 将值转换为 RawStdBase64 编码的字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawStdBase64)] [[play](https://go.dev/play/p/wSAr3sfkDcv)] -- **ToRawUrlBase64** : 将值转换为RawUrlBase64编码的字符串。 +- **ToRawUrlBase64** : 将值转换为 RawUrlBase64 编码的字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawUrlBase64)] [[play](https://go.dev/play/p/HwdDPFcza1O)] -- **ToBigInt** : 将整数转为*big.Int。 +- **ToBigInt** : 将整数转为\*big.Int。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToBigInt)] [[play](https://go.dev/play/p/X3itkCxwB_x)] @@ -474,19 +497,19 @@ import "github.com/duke-git/lancet/v2/cryptor" - **RsaDecrypt** : 用私钥文件 rsa 解密数据。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaDecrypt)] [[play](https://go.dev/play/p/7_zo6mrx-eX)] -- **GenerateRsaKeyPair** : 创建rsa公钥私钥和key。 +- **GenerateRsaKeyPair** : 创建 rsa 公钥私钥和 key。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#GenerateRsaKeyPair)] [[play](https://go.dev/play/p/sSVmkfENKMz)] -- **RsaEncryptOAEP** : rsa OAEP加密。 +- **RsaEncryptOAEP** : rsa OAEP 加密。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaEncryptOAEP)] [[play](https://go.dev/play/p/sSVmkfENKMz)] -- **RsaDecryptOAEP** : rsa OAEP解密。 +- **RsaDecryptOAEP** : rsa OAEP 解密。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaDecryptOAEP)] [[play](https://go.dev/play/p/sSVmkfENKMz)] -- **RsaSign** : 应用RSA算法签名数据。 +- **RsaSign** : 应用 RSA 算法签名数据。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaSign)] [[play](https://go.dev/play/p/qhsbf8BJ6Mf)] -- **RsaVerifySign** : 验证数据的签名是否符合RSA算法。 +- **RsaVerifySign** : 验证数据的签名是否符合 RSA 算法。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaVerifySign)] [[play](https://go.dev/play/p/qhsbf8BJ6Mf)] @@ -645,7 +668,7 @@ import "github.com/duke-git/lancet/v2/datetime" - **DaysBetween** : 返回两个日期之间的天数差。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#DaysBetween)] [[play](https://go.dev/play/p/qD6qGb3TbOy)] -- **GenerateDatetimesBetween** : 生成从start到end的所有日期时间的字符串列表。 +- **GenerateDatetimesBetween** : 生成从 start 到 end 的所有日期时间的字符串列表。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#GenerateDatetimesBetween)] [[play](https://go.dev/play/p/6kHBpAxD9ZC)] - **Min** : 返回最早时间。 @@ -658,7 +681,6 @@ import "github.com/duke-git/lancet/v2/datetime" [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#MaxMin)] [[play](https://go.dev/play/p/rbW51cDtM_2)] -

8. datastructure 包含一些普通的数据结构实现。例如:list, linklist, stack, queue, set, tree, graph。       回到目录

```go @@ -702,7 +724,7 @@ import "github.com/duke-git/lancet/v2/eventbus" #### 函数列表: -- **NewEventBus** : 创建EventBus实例。 +- **NewEventBus** : 创建 EventBus 实例。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#NewEventBus)] [[play](https://go.dev/play/p/gHbOPV_NUOJ)] - **Subscribe** : 订阅具有特定事件主题和监听函数的事件。支持异步,事件优先级,事件过滤器。 @@ -726,7 +748,7 @@ import "github.com/duke-git/lancet/v2/eventbus" - **GetAllListenersCount** : 获取所有事件的监听器数量。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetAllListenersCount)] [[play](https://go.dev/play/p/PUlr0xcpEOz)] -- **GetEvents** : 获取所有事件的topic。 +- **GetEvents** : 获取所有事件的 topic。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetEvents)] [[play](https://go.dev/play/p/etgjjcOtAjX)] - **SetErrorHandler** : 设置事件的错误处理函数。 @@ -777,6 +799,9 @@ import "github.com/duke-git/lancet/v2/fileutil" - **RemoveFile** : 删除文件。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#RemoveFile)] [[play](https://go.dev/play/p/P2y0XW8a1SH)] +- **RemoveDir** : 删除目录,支持传入删除前的回调函数。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#RemoveDir)] + [[play](https://go.dev/play/p/todo)] - **ReadFileToString** : 读取文件内容并返回字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ReadFileToString)] [[play](https://go.dev/play/p/cmfwp_5SQTp)] @@ -809,9 +834,9 @@ import "github.com/duke-git/lancet/v2/fileutil" - **ReadCsvFile** : 读取 csv 文件内容到切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ReadCsvFile)] [[play](https://go.dev/play/p/OExTkhGEd3_u)] -- **WriteCsvFile** : 向csv文件写入切片数据。 +- **WriteCsvFile** : 向 csv 文件写入切片数据。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteCsvFile)] -- **WriteMapsToCsv** : 将map切片写入csv文件中。 +- **WriteMapsToCsv** : 将 map 切片写入 csv 文件中。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteMapsToCsv)] [[play](https://go.dev/play/p/umAIomZFV1c)] - **WriteBytesToFile** : 将 bytes 写入文件。 @@ -820,7 +845,7 @@ import "github.com/duke-git/lancet/v2/fileutil" - **WriteStringToFile** : 将字符串写入文件。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#WriteStringToFile)] [[play](https://go.dev/play/p/GhLS6d8lH_g)] -- **ReadFile** : 读取文件或者URL。 +- **ReadFile** : 读取文件或者 URL。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ReadFile)] - **ChunkRead** : 从文件的指定偏移读取块并返回块内所有行。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ChunkRead)] @@ -828,11 +853,10 @@ import "github.com/duke-git/lancet/v2/fileutil" - **ParallelChunkRead** : 并行读取文件并将每个块的行发送到指定通道。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ParallelChunkRead)] [[play](https://go.dev/play/p/teMXnCsdSEw)] -- **GetExeOrDllVersion** : 返回exe,dll文件版本号(仅Window平台)。 +- **GetExeOrDllVersion** : 返回 exe,dll 文件版本号(仅 Window 平台)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#GetExeOrDllVersion)] [[play](https://go.dev/play/p/iLRrDBhE38E)] -

11. formatter 格式化器包含一些数据格式化处理方法。       回到目录

```go @@ -901,33 +925,31 @@ import "github.com/duke-git/lancet/v2/function" - **Pipeline** : 从右至左执行函数列表。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Pipeline)] [[play](https://go.dev/play/p/mPdUVvj6HD6)] -- **AcceptIf** : AcceptIf函数会返回另一个函数,该函数的签名与apply函数相同,但同时还会包含一个布尔值来表示成功或失败。 +- **AcceptIf** : AcceptIf 函数会返回另一个函数,该函数的签名与 apply 函数相同,但同时还会包含一个布尔值来表示成功或失败。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#AcceptIf)] [[play](https://go.dev/play/p/XlXHHtzCf7d)] -- **And** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑and操作。 +- **And** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑 and 操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#And)] [[play](https://go.dev/play/p/dTBHJMQ0zD2)] -- **Or** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑or操作。 +- **Or** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑 or 操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Or)] [[play](https://go.dev/play/p/LitCIsDFNDA)] - **Negate** : 返回一个谓词函数,该谓词函数表示当前谓词的逻辑否定。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Negate)] [[play](https://go.dev/play/p/jbI8BtgFnVE)] -- **Nor** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑非或nor的操作。 +- **Nor** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑非或 nor 的操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Nor)] [[play](https://go.dev/play/p/2KdCoBEOq84)] -- **Nand** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑非与nand的操作。 +- **Nand** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑非与 nand 的操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Nand)] [[play](https://go.dev/play/p/Rb-FdNGpgSO)] -- **Xnor** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑异或xnor的操作。 +- **Xnor** : 返回一个复合谓词判断函数,该判断函数表示一组谓词的逻辑异或 xnor 的操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Xnor)] [[play](https://go.dev/play/p/FJxko8SFbqc)] - **Watcher** : Watcher 用于记录代码执行时间。可以启动/停止/重置手表定时器。获取函数执行的时间。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/function.md#Watcher)] [[play](https://go.dev/play/p/l2yrOpCLd1I)] - -

13. maputil 包括一些操作 map 的函数。       回到目录

```go @@ -1005,13 +1027,13 @@ import "github.com/duke-git/lancet/v2/maputil" - **GetOrSet** : 返回给定键的值,如果不存在则设置该值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#GetOrSet)] [[play](https://go.dev/play/p/IVQwO1OkEJC)] -- **MapToStruct** : 将map转成struct。 +- **MapToStruct** : 将 map 转成 struct。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#MapToStruct)] [[play](https://go.dev/play/p/7wYyVfX38Dp)] -- **ToSortedSlicesDefault** : 将map的key和value转化成两个根据key的值从小到大排序的切片,value切片中元素的位置与key对应。 +- **ToSortedSlicesDefault** : 将 map 的 key 和 value 转化成两个根据 key 的值从小到大排序的切片,value 切片中元素的位置与 key 对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#ToSortedSlicesDefault)] [[play](https://go.dev/play/p/43gEM2po-qy)] -- **ToSortedSlicesWithComparator** : 将map的key和value转化成两个使用比较器函数根据key的值自定义排序规则的切片,value切片中元素的位置与key对应。 +- **ToSortedSlicesWithComparator** : 将 map 的 key 和 value 转化成两个使用比较器函数根据 key 的值自定义排序规则的切片,value 切片中元素的位置与 key 对应。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#ToSortedSlicesWithComparator)] [[play](https://go.dev/play/p/0nlPo6YLdt3)] - **NewOrderedMap** : 创建有序映射。有序映射是键值对的集合,其中键是唯一的,并且保留键插入的顺序。 @@ -1026,7 +1048,7 @@ import "github.com/duke-git/lancet/v2/maputil" - **OrderedMap_Delete** : 删除给定键的键值对。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_Delete)] [[play](ttps://go.dev/play/p/5bIi4yaZ3K-)] -- **OrderedMap_Clear** : 清空map数据。 +- **OrderedMap_Clear** : 清空 map 数据。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_Clear)] [[play](https://go.dev/play/p/8LwoJyEfuFr)] - **OrderedMap_Front** : 返回第一个键值对。 @@ -1050,7 +1072,7 @@ import "github.com/duke-git/lancet/v2/maputil" - **OrderedMap_Len** : 返回键值对的数量。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_Len)] [[play](https://go.dev/play/p/cLe6z2VX5N-)] -- **OrderedMap_Contains** : 如果给定的键存在则返回true。 +- **OrderedMap_Contains** : 如果给定的键存在则返回 true。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_Contains)] [[play](https://go.dev/play/p/QuwqqnzwDNX)] - **OrderedMap_Iter** : 返回按顺序产生键值对的通道。 @@ -1059,13 +1081,13 @@ import "github.com/duke-git/lancet/v2/maputil" - **OrderedMap_ReverseIter** : 返回以相反顺序产生键值对的通道。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_ReverseIter)] [[play](https://go.dev/play/p/8Q0ssg6hZzO)] -- **OrderedMap_SortByKey** : 使用传入的比较函数排序map key。 +- **OrderedMap_SortByKey** : 使用传入的比较函数排序 map key。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_SortByKey)] [[play](https://go.dev/play/p/N7hjD_alZPq)] -- **OrderedMap_MarshalJSON** : 实现json.Marshaler接口。 +- **OrderedMap_MarshalJSON** : 实现 json.Marshaler 接口。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_MarshalJSON)] [[play](https://go.dev/play/p/C-wAwydIAC7)] -- **OrderedMap_UnmarshalJSON** : 实现json.Unmarshaler接口。 +- **OrderedMap_UnmarshalJSON** : 实现 json.Unmarshaler 接口。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#OrderedMap_UnmarshalJSON)] [[play](https://go.dev/play/p/8C3MvJ3-mut)] - **NewConcurrentMap** : ConcurrentMap 协程安全的 map 结构。 @@ -1092,12 +1114,15 @@ import "github.com/duke-git/lancet/v2/maputil" - **ConcurrentMap_Range** : 为 map 中每个键和值顺序调用迭代器。 如果 iterator 返回 false,则停止迭代。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#ConcurrentMap_Range)] [[play](https://go.dev/play/p/iqcy7P8P0Pr)] -- **SortByKey** : 对传入的map根据key进行排序。 +- **SortByKey** : 对传入的 map 根据 key 进行排序。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#SortByKey)] [[play](https://go.dev/play/p/PVdmBSnm6P_W)] - **GetOrDefault** : 返回给定键的值,如果键不存在,则返回默认值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#GetOrDefault)] [[play](https://go.dev/play/p/99QjSYSBdiM)] +- **FindValuesBy** : 返回一个切片,包含满足给定谓词判断函数的 map 中的值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/maputil.md#FindValuesBy)] + [[play](https://go.dev/play/p/todo)]

14. mathutil 包实现了一些数学计算的函数。       回到目录

@@ -1143,16 +1168,16 @@ import "github.com/duke-git/lancet/v2/mathutil" - **TruncRound** : 截短 n 位小数(不进行四舍五入)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#TruncRound)] [[play](https://go.dev/play/p/aumarSHIGzP)] -- **CeilToFloat** : 向上舍入(进一法),保留n位小数。 +- **CeilToFloat** : 向上舍入(进一法),保留 n 位小数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#CeilToFloat)] [[play](https://go.dev/play/p/8hOeSADZPCo)] -- **CeilToString** : 向上舍入(进一法),保留n位小数,返回字符串。 +- **CeilToString** : 向上舍入(进一法),保留 n 位小数,返回字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#CeilToString)] [[play](https://go.dev/play/p/wy5bYEyUKKG)] -- **FloorToFloat** : 向下舍入(去尾法),保留n位小数。 +- **FloorToFloat** : 向下舍入(去尾法),保留 n 位小数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#FloorToFloat)] [[play](https://go.dev/play/p/vbCBrQHZEED)] -- **FloorToString** : 向下舍入(去尾法),保留n位小数,返回字符串。 +- **FloorToString** : 向下舍入(去尾法),保留 n 位小数,返回字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#FloorToString)] [[play](https://go.dev/play/p/Qk9KPd2IdDb)] - **Range** : 根据指定的起始值和数量,创建一个数字切片。 @@ -1203,10 +1228,10 @@ import "github.com/duke-git/lancet/v2/mathutil" - **StdDev** : 计算标准差。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#StdDev)] [[play](https://go.dev/play/p/FkNZDXvHD2l)] -- **Permutation** : 计算排列数P(n, k)。 +- **Permutation** : 计算排列数 P(n, k)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Permutation)] [[play](https://go.dev/play/p/MgobwH_FOxj)] -- **Combination** : 计算组合数C(n, k)。 +- **Combination** : 计算组合数 C(n, k)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Combination)] [[play](https://go.dev/play/p/ENFQRDQUFi9)] @@ -1282,6 +1307,12 @@ import "github.com/duke-git/lancet/v2/netutil" - **IsTelnetConnected** : 检查能否 telnet 到主机。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/netutil.md#IsTelnetConnected)] [[play](https://go.dev/play/p/yiLCGtQv_ZG)] +- **BuildUrl** : 创建 url 字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/netutil.md#BuildUrl)] + [[play](https://go.dev/play/p/todo)] +- **AddQueryParams** : 向 url 添加查询参数。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/netutil.md#AddQueryParams)] + [[play](https://go.dev/play/p/todo)]

16. pointer 包支持一些指针类型的操作。       回到目录

@@ -1339,28 +1370,28 @@ import "github.com/duke-git/lancet/v2/random" - **UUIdV4** : 生成 UUID v4 字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#UUIdV4)] [[play](https://go.dev/play/p/_Z9SFmr28ft)] -- **RandUniqueIntSlice** : 生成一个不重复的随机int切片。 +- **RandUniqueIntSlice** : 生成一个不重复的随机 int 切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandUniqueIntSlice)] [[play](https://go.dev/play/p/uBkRSOz73Ec)] - **RandSymbolChar** : 生成给定长度的随机符号字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandSymbolChar)] [[play](https://go.dev/play/p/Im6ZJxAykOm)] -- **RandFloat** : 生成随机float64数字,可以指定范围和精度。 +- **RandFloat** : 生成随机 float64 数字,可以指定范围和精度。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandFloat)] [[play](https://go.dev/play/p/zbD_tuobJtr)] -- **RandFloats** : 生成随机float64数字切片,可以指定长度,范围和精度. +- **RandFloats** : 生成随机 float64 数字切片,可以指定长度,范围和精度. [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandFloats)] [[play](https://go.dev/play/p/uBkRSOz73Ec)] -- **RandStringSlice** : 生成随机字符串slice。 +- **RandStringSlice** : 生成随机字符串 slice。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandStringSlice)] [[play](https://go.dev/play/p/2_-PiDv3tGn)] -- **RandBool** : 生成随机bool值(true or false)。 +- **RandBool** : 生成随机 bool 值(true or false)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandBool)] [[play](https://go.dev/play/p/to6BLc26wBv)] -- **RandBoolSlice** : 生成特定长度的随机bool slice。 +- **RandBoolSlice** : 生成特定长度的随机 bool slice。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandBoolSlice)] [[play](https://go.dev/play/p/o-VSjPjnILI)] -- **RandIntSlice** : 生成一个特定长度的随机int切片,数值范围[min, max)。 +- **RandIntSlice** : 生成一个特定长度的随机 int 切片,数值范围[min, max)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandIntSlice)] [[play](https://go.dev/play/p/GATTQ5xTEG8)] - **RandFromGivenSlice** : 从给定切片中随机生成元素。 @@ -1390,7 +1421,7 @@ import "github.com/duke-git/lancet/v2/retry" - **RetryFunc** : 重试执行的函数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryFunc)] [[play](https://go.dev/play/p/nk2XRmagfVF)] -- **RetryTimes** : 设置重试次数,默认5。 +- **RetryTimes** : 设置重试次数,默认 5。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryTimes)] [[play](https://go.dev/play/p/ssfVeU2SwLO)] - **BackoffStrategy** : 定义计算退避间隔的方法的接口。 @@ -1405,8 +1436,6 @@ import "github.com/duke-git/lancet/v2/retry" [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryWithExponentialWithJitterBackoff)] [[play](https://go.dev/play/p/xp1avQmn16X)] - -

19. slice 包含操作切片的方法集合。        回到目录

```go @@ -1511,7 +1540,7 @@ import "github.com/duke-git/lancet/v2/slice" - **ForEach** : 遍历切片的元素并为每个元素调用 iteratee 函数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#ForEach)] [[play](https://go.dev/play/p/DrPaa4YsHRF)] -- **ForEachConcurrent** : 对slice并发执行foreach操作。 +- **ForEachConcurrent** : 对 slice 并发执行 foreach 操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#ForEachConcurrent)] [[play](https://go.dev/play/p/kT4XW7DKVoV)] - **ForEachWithBreak** : 遍历切片的元素并为每个元素调用 iteratee 函数,当 iteratee 函数返回 false 时,终止遍历。 @@ -1544,7 +1573,7 @@ import "github.com/duke-git/lancet/v2/slice" - **Map** : 对 slice 中的每个元素执行 map 函数以创建一个新切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Map)] [[play](https://go.dev/play/p/biaTefqPquw)] -- **MapConcurrent** : 对slice并发执行map操作。 +- **MapConcurrent** : 对 slice 并发执行 map 操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#MapConcurrent)] [[play](https://go.dev/play/p/H1ehfPkPen0)] - **Merge** : 合并多个切片(不会消除重复元素)。 @@ -1553,7 +1582,7 @@ import "github.com/duke-git/lancet/v2/slice" - **Reverse** : 反转切片中的元素顺序。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Reverse)] [[play](https://go.dev/play/p/8uI8f1lwNrQ)] -- **ReverseCopy** : 反转切片中的元素顺序, 不改变原slice。 +- **ReverseCopy** : 反转切片中的元素顺序, 不改变原 slice。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#ReverseCopy)] [[play](https://go.dev/play/p/c9arEaP7Cg-)] - **Reducedeprecated** : 将切片中的元素依次运行 iteratee 函数,返回运行结果。(废弃:建议使用 ReduceBy) @@ -1565,7 +1594,7 @@ import "github.com/duke-git/lancet/v2/slice" - **ReduceRight** : 类似 ReduceBy 操作,迭代切片元素顺序从右至左。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#ReduceRight)] [[play](https://go.dev/play/p/qT9dZC03A1K)] -- **ReduceConcurrent** : 对切片元素执行并发reduce操作。 +- **ReduceConcurrent** : 对切片元素执行并发 reduce 操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#ReduceConcurrent)] [[play](https://go.dev/play/p/Tjwe6OtaG07)] - **Replace** : 返回切片的副本,其中前 n 个不重叠的 old 替换为 new。 @@ -1628,7 +1657,7 @@ import "github.com/duke-git/lancet/v2/slice" - **UniqueByComparator** : 使用提供的比较器函数从输入切片中移除重复元素。此函数保持元素的顺序。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#UniqueByComparator)] [[play](https://go.dev/play/p/rwSacr-ZHsR)] -- **UniqueByField** : 根据struct字段对struct切片去重复。 +- **UniqueByField** : 根据 struct 字段对 struct 切片去重复。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#UniqueByField)] [[play](https://go.dev/play/p/6cifcZSPIGu)] - **UniqueByConcurrent** : 并发的从输入切片中移除重复元素,结果保持元素的顺序。 @@ -1651,13 +1680,13 @@ import "github.com/duke-git/lancet/v2/slice" - **Join** : 用指定的分隔符链接切片元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Join)] [[play](https://go.dev/play/p/huKzqwNDD7V)] -- **Partition** : 根据给定的predicate判断函数分组切片元素。 +- **Partition** : 根据给定的 predicate 判断函数分组切片元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Partition)] [[play](https://go.dev/play/p/lkQ3Ri2NQhV)] -- **Random** : 随机返回切片中元素以及下标, 当切片长度为0时返回下标-1。 +- **Random** : 随机返回切片中元素以及下标, 当切片长度为 0 时返回下标-1。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Random)] [[play](https://go.dev/play/p/UzpGQptWppw)] -- **SetToDefaultIf** : 根据给定给定的predicate判定函数来修改切片中的元素。 +- **SetToDefaultIf** : 根据给定给定的 predicate 判定函数来修改切片中的元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#SetToDefaultIf)] [[play](https://go.dev/play/p/9AXGlPRC0-A)] - **Break** : 根据判断函数将切片分成两部分。它开始附加到与函数匹配的第一个元素之后的第二个切片。第一个匹配之后的所有元素都包含在第二个切片中,无论它们是否与函数匹配。 @@ -1704,13 +1733,13 @@ import "github.com/duke-git/lancet/v2/stream" - **Concat** : 创建一个延迟连接 stream,其元素是第一个 stream 的所有元素,后跟第二个 stream 的全部元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#Concat)] [[play](https://go.dev/play/p/HM4OlYk_OUC)] -- **Distinct** : 创建并返回一个stream,用于删除重复的项。 +- **Distinct** : 创建并返回一个 stream,用于删除重复的项。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#Distinct)] [[play](https://go.dev/play/p/eGkOSrm64cB)] -- **Filter** : 返回一个通过判定函数的stream。 +- **Filter** : 返回一个通过判定函数的 stream。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#Filter)] [[play](https://go.dev/play/p/MFlSANo-buc)] -- **FilterConcurrent** : 对slice并发执行filter操作。 +- **FilterConcurrent** : 对 slice 并发执行 filter 操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#FilterConcurrent)] [[play](https://go.dev/play/p/t_pkwerIRVx)] - **Map** : 返回一个 stream,该 stream 由将给定函数应用于源 stream 元素的元素组成。 @@ -1767,10 +1796,10 @@ import "github.com/duke-git/lancet/v2/stream" - **ToSlice** : 返回 stream 中的元素切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#ToSlice)] [[play](https://go.dev/play/p/jI6_iZZuVFE)] -- **IndexOf** : 返回在stream中找到值的第一个匹配项的索引,如果找不到值,则返回-1。 +- **IndexOf** : 返回在 stream 中找到值的第一个匹配项的索引,如果找不到值,则返回-1。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#IndexOf)] [[play](https://go.dev/play/p/tBV5Nc-XDX2)] -- **LastIndexOf** : 返回在stream中找到值的最后一个匹配项的索引,如果找不到值,则返回-1。 +- **LastIndexOf** : 返回在 stream 中找到值的最后一个匹配项的索引,如果找不到值,则返回-1。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#LastIndexOf)] [[play](https://go.dev/play/p/CjeoNw2eac_G)] @@ -1933,7 +1962,7 @@ import "github.com/duke-git/lancet/v2/strutil" - **RemoveWhiteSpace** : 删除字符串中的空格。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#RemoveWhiteSpace)] [[play](https://go.dev/play/p/HzLC9vsTwkf)] -- **SubInBetween** : 获取字符串中指定的起始字符串start和终止字符串end直接的子字符串。 +- **SubInBetween** : 获取字符串中指定的起始字符串 start 和终止字符串 end 直接的子字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#SubInBetween)] [[play](https://go.dev/play/p/EDbaRvjeNsv)] - **HammingDistance** : 计算两个字符串之间的汉明距离。 @@ -1951,7 +1980,7 @@ import "github.com/duke-git/lancet/v2/strutil" - **Rotate** : 按指定的字符数旋转字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#Rotate)] [[play](https://go.dev/play/p/Kf03iOeT5bd)] -- **TemplateReplace** : 将模板字符串中的占位符替换为map中的相应值。 +- **TemplateReplace** : 将模板字符串中的占位符替换为 map 中的相应值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#TemplateReplace)] [[play](https://go.dev/play/p/cXSuFvyZqv9)] - **RegexMatchAllGroups** : 使用正则表达式匹配字符串中的所有子组并返回结果。 @@ -1964,7 +1993,6 @@ import "github.com/duke-git/lancet/v2/strutil" [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#FindAllOccurrences)] [[play](https://go.dev/play/p/uvyA6azGLB1)] -

23. system 包含 os, runtime, shell command 的相关函数。       回到目录

```go @@ -2009,12 +2037,10 @@ import "github.com/duke-git/lancet/v2/system" - **KillProcess** : 杀掉进程。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/system.md#KillProcess)] [[play](https://go.dev/play/p/XKmvV-ExBWa)] -- **GetProcessInfo** : 根据进程id获取进程信息。 +- **GetProcessInfo** : 根据进程 id 获取进程信息。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/system.md#GetProcessInfo)] [[play](https://go.dev/play/p/NQDVywEYYx7)] - -

24. Tuple 包实现一个元组数据类型。       回到目录

```go @@ -2176,7 +2202,7 @@ import "github.com/duke-git/lancet/v2/validator" - **IsCreditCard** : 验证字符串是否是信用卡号码。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsCreditCard)] [[play](https://go.dev/play/p/sNwwL6B0-v4)] -- **IsDns** : 验证字符串是否是有效dns。 +- **IsDns** : 验证字符串是否是有效 dns。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsDns)] [[play](https://go.dev/play/p/jlYApVLLGTZ)] - **IsEmail** : 验证字符串是否是有效电子邮件地址。 @@ -2197,6 +2223,9 @@ import "github.com/duke-git/lancet/v2/validator" - **IsNumberStr** : 验证字符串是否是可以转换为数字。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsNumberStr)] [[play](https://go.dev/play/p/LzaKocSV79u)] +- **IsAlphaNumeric** : 验证字符串是字母或数字。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsAlphaNumeric)] + [[play](https://go.dev/play/p/todo)] - **IsJSON** : 验证字符串是否是有效 json。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsJSON)] [[play](https://go.dev/play/p/8Kip1Itjiil)] @@ -2212,13 +2241,13 @@ import "github.com/duke-git/lancet/v2/validator" - **IsIp** : 验证字符串是否是 ip 地址。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIp)] [[play](https://go.dev/play/p/FgcplDvmxoD)] -- **IsIpV4** : 验证字符串是否是ipv4地址。 +- **IsIpV4** : 验证字符串是否是 ipv4 地址。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpV4)] [[play](https://go.dev/play/p/zBGT99EjaIu)] -- **IsIpV6** : 验证字符串是否是ipv6地址。 +- **IsIpV6** : 验证字符串是否是 ipv6 地址。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpV6)] [[play](https://go.dev/play/p/AHA0r0AzIdC)] -- **IsIpPort** : 检查字符串是否是ip:port格式。 +- **IsIpPort** : 检查字符串是否是 ip:port 格式。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpPort)] [[play](https://go.dev/play/p/xUmls_b9L29)] - **IsStrongPassword** : 验证字符串是否是强密码:(字母+数字+特殊字符)。 @@ -2233,10 +2262,10 @@ import "github.com/duke-git/lancet/v2/validator" - **IsZeroValue** : 判断传入的参数值是否为零值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsZeroValue)] [[play](https://go.dev/play/p/UMrwaDCi_t4)] -- **IsGBK** : 检查数据编码是否为gbk(汉字内部代码扩展规范)。 +- **IsGBK** : 检查数据编码是否为 gbk(汉字内部代码扩展规范)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsGBK)] [[play](https://go.dev/play/p/E2nt3unlmzP)] -- **IsASCII** : 验证字符串全部为ASCII字符。 +- **IsASCII** : 验证字符串全部为 ASCII 字符。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsASCII)] [[play](https://go.dev/play/p/hfQNPLX0jNa)] - **IsPrintable** : 检查字符串是否全部为可打印字符。 @@ -2251,13 +2280,13 @@ import "github.com/duke-git/lancet/v2/validator" - **IsBase64URL** : 检查字符串是否是有效的 base64 url。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsBase64URL)] [[play](https://go.dev/play/p/vhl4mr8GZ6S)] -- **IsJWT** : 检查字符串是否是有效的JSON Web Token (JWT)。 +- **IsJWT** : 检查字符串是否是有效的 JSON Web Token (JWT)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsJWT)] [[play](https://go.dev/play/p/R6Op7heJbKI)] -- **IsVisa** : 检查字符串是否是有效的visa卡号。 +- **IsVisa** : 检查字符串是否是有效的 visa 卡号。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsVisa)] [[play](https://go.dev/play/p/SdS2keOyJsl)] -- **IsMasterCard** : 检查字符串是否是有效的MasterCard卡号。 +- **IsMasterCard** : 检查字符串是否是有效的 MasterCard 卡号。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsMasterCard)] [[play](https://go.dev/play/p/CwWBFRrG27b)] - **IsAmericanExpress** : 检查字符串是否是有效的 American Express 卡号。 @@ -2293,31 +2322,31 @@ import "github.com/duke-git/lancet/v2/xerror" - **XError_Unwrap** : 解构 XEerror 为 error 对象。适配 github.com/pkg/errors。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Unwrap) [[play](https://go.dev/play/p/VUXJ8BST4c6)] -- **XError_With** : 添加与XError对象的键和值。 +- **XError_With** : 添加与 XError 对象的键和值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_With)] [[play](https://go.dev/play/p/ow8UISXX_Dp)] -- **XError_Id** : 设置XError对象的id。 +- **XError_Id** : 设置 XError 对象的 id。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Id)] [[play](https://go.dev/play/p/X6HBlsy58U9)] -- **XError_Is** : 检查目标error是否为XError,两个错误中的error.id是否匹配。 +- **XError_Is** : 检查目标 error 是否为 XError,两个错误中的 error.id 是否匹配。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Is)] [[play](https://go.dev/play/p/X6HBlsy58U9)] -- **XError_Values** : 返回由With设置的键和值的映射。将合并所有XError键和值。 +- **XError_Values** : 返回由 With 设置的键和值的映射。将合并所有 XError 键和值。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Values)] [[play](https://go.dev/play/p/ow8UISXX_Dp)] -- **XError_StackTrace** : 返回与pkg/error兼容的堆栈信息。 +- **XError_StackTrace** : 返回与 pkg/error 兼容的堆栈信息。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_StackTrace)] [[play](https://go.dev/play/p/6FAvSQpa7pc)] -- **XError_Info** : 返回可打印的XError对象信息。 +- **XError_Info** : 返回可打印的 XError 对象信息。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Info)] [[play](https://go.dev/play/p/1ZX0ME1F-Jb)] -- **XError_Error** : 实现标准库的error接口。 +- **XError_Error** : 实现标准库的 error 接口。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Error)] [[play](https://go.dev/play/p/w4oWZts7q7f)] -- **TryUnwrap** : 检查error, 如果err为nil则展开,则它返回一个有效值,如果err不是nil则Unwrap使用err发生panic。 +- **TryUnwrap** : 检查 error, 如果 err 为 nil 则展开,则它返回一个有效值,如果 err 不是 nil 则 Unwrap 使用 err 发生 panic。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#TryUnwrap)] [[play](https://go.dev/play/p/acyZVkNZEeW)] -- **TryCatch** : 简单实现的java风格异常处理(try-catch-finally)。 +- **TryCatch** : 简单实现的 java 风格异常处理(try-catch-finally)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#TryCatch)] [[play](https://go.dev/play/p/D5Mdb0mRj0P)] @@ -2327,7 +2356,7 @@ import "github.com/duke-git/lancet/v2/xerror" ## 贡献者 -感谢所有为lancet贡献过代码的人! +感谢所有为 lancet 贡献过代码的人! @@ -2335,4 +2364,4 @@ import "github.com/duke-git/lancet/v2/xerror" ## GitHub Stars -[![Star History Chart](https://api.star-history.com/svg?repos=duke-git/lancet&type=Date)](https://star-history.com/#duke-git/lancet&Date) \ No newline at end of file +[![Star History Chart](https://api.star-history.com/svg?repos=duke-git/lancet&type=Date)](https://star-history.com/#duke-git/lancet&Date) diff --git a/docs/api/packages/concurrency.md b/docs/api/packages/concurrency.md index 8444090..7706d11 100644 --- a/docs/api/packages/concurrency.md +++ b/docs/api/packages/concurrency.md @@ -41,12 +41,11 @@ import ( - [NewKeyedLocker](#NewKeyedLocker) - [KeyedLocker_Do](#Do) - [NewRWKeyedLocker](#NewRWKeyedLocker) -- [RWKeyedLocker_RLock](#RLock) -- [RWKeyedLocker_Lock](#Lock) +- [RLock](#RLock) +- [Lock](#Lock) - [NewTryKeyedLocker](#NewTryKeyedLocker) -- [TryKeyedLocker_TryLock](#TryLock) -- [TryKeyedLocker_Unlock](#Unlock) - +- [TryLock](#TryLock) +- [Unlock](#Unlock)
@@ -525,7 +524,7 @@ func main() { } ``` -### KeyedLocker_Do +### Do

为指定的键获取锁并执行提供的函数。

@@ -591,6 +590,7 @@ func main() { ```go func NewRWKeyedLocker[K comparable](ttl time.Duration) *RWKeyedLocker[K] ``` + 示例:[运行](https://go.dev/play/p/todo) ```go @@ -630,7 +630,7 @@ func main() { } ``` -### RWKeyedLocker_RLock +### RLock

RLock为指定的键获取读锁并执行提供的函数。

@@ -639,6 +639,7 @@ func main() { ```go func (l *RWKeyedLocker[K]) RLock(ctx context.Context, key K, fn func()) error ``` + 示例:[运行](https://go.dev/play/p/todo) ```go @@ -678,15 +679,16 @@ func main() { } ``` -### RWKeyedLocker_Lock +### Lock -

RLock为指定的键获取锁并执行提供的函数。

+

Lock为指定的键获取锁并执行提供的函数。

函数签名: ```go func (l *RWKeyedLocker[K]) Lock(ctx context.Context, key K, fn func()) error ``` + 示例:[运行](https://go.dev/play/p/todo) ```go @@ -733,8 +735,9 @@ func main() { 函数签名: ```go -func NewTryKeyedLocker[K comparable]() *TryKeyedLocker[K] +func NewTryKeyedLocker[K comparable]() *TryKeyedLocker[K] ``` + 示例:[运行](https://go.dev/play/p/todo) ```go @@ -766,7 +769,7 @@ func main() { } ``` -### TryKeyedLocker_TryLock +### TryLock

TryLock尝试获取指定键的锁。如果锁成功获取,则返回true,否则返回false。

@@ -807,7 +810,7 @@ func main() { } ``` -### TryKeyedLocker_Unlock +### Unlock

释放指定键的锁。

@@ -846,4 +849,4 @@ func main() { //Lock acquired //Lock released } -``` \ No newline at end of file +``` diff --git a/docs/api/packages/netutil.md b/docs/api/packages/netutil.md index 60d2067..0818d90 100644 --- a/docs/api/packages/netutil.md +++ b/docs/api/packages/netutil.md @@ -48,7 +48,6 @@ import ( - [UploadFile](#UploadFile) - [IsPingConnected](#IsPingConnected) - [IsTelnetConnected](#IsTelnetConnected) -- [IsTelnetConnected](#IsTelnetConnected) - [BuildUrl](#BuildUrl) - [AddQueryParams](#AddQueryParams) @@ -1113,4 +1112,4 @@ func main() { // https://example.com/query?a=foo&a=bar&b=baz // } -``` \ No newline at end of file +``` diff --git a/docs/api/packages/validator.md b/docs/api/packages/validator.md index 5384829..46b6a7c 100644 --- a/docs/api/packages/validator.md +++ b/docs/api/packages/validator.md @@ -824,6 +824,43 @@ func main() { } ``` +### IsAlphaNumeric + +

验证字符串是字母或数字。

+ +函数签名: + +```go +func IsAlphaNumeric(s string) bool +``` + +示例:[运行](https://go.dev/play/p/todo) + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/validator" +) + +func main() { + result1 := validator.IsAlphaNumeric("ABC") + result2 := validator.IsAlphaNumeric("123") + result3 := validator.IsAlphaNumeric("abc123") + result4 := validator.IsAlphaNumeric("abc123@#$") + + fmt.Println(result1) + fmt.Println(result2) + fmt.Println(result3) + fmt.Println(result4) + + // Output: + // true + // true + // true + // false +} +``` + ### IsJSON

验证字符串是否是有效json。

diff --git a/docs/en/api/packages/concurrency.md b/docs/en/api/packages/concurrency.md index 0d2b66c..0ba938a 100644 --- a/docs/en/api/packages/concurrency.md +++ b/docs/en/api/packages/concurrency.md @@ -1,16 +1,18 @@ # Concurrency + Package concurrency contain some functions to support concurrent programming. eg, goroutine, channel.
## Source: -- [https://github.com/duke-git/lancet/blob/main/concurrency/channel.go](https://github.com/duke-git/lancet/blob/main/concurrency/channel.go) +- [https://github.com/duke-git/lancet/blob/main/concurrency/channel.go](https://github.com/duke-git/lancet/blob/main/concurrency/channel.go) - [https://github.com/duke-git/lancet/blob/main/concurrency/keyed_locker.go](https://github.com/duke-git/lancet/blob/main/concurrency/keyed_locker.go)
## Usage: + ```go import ( "github.com/duke-git/lancet/v2/concurrency" @@ -23,34 +25,36 @@ import ( ### Channel -- [NewChannel](#NewChannel) -- [Bridge](#Bridge) -- [FanIn](#FanIn) -- [Generate](#Generate) -- [Or](#Or) -- [OrDone](#OrDone) -- [Repeat](#Repeat) -- [RepeatFn](#RepeatFn) -- [Take](#Take) -- [Tee](#Tee) +- [NewChannel](#NewChannel) +- [Bridge](#Bridge) +- [FanIn](#FanIn) +- [Generate](#Generate) +- [Or](#Or) +- [OrDone](#OrDone) +- [Repeat](#Repeat) +- [RepeatFn](#RepeatFn) +- [Take](#Take) +- [Tee](#Tee) ### KeyedLocker - [NewKeyedLocker](#NewKeyedLocker) -- [KeyedLocker_Do](#Do) +- [Do](#Do) - [NewRWKeyedLocker](#NewRWKeyedLocker) -- [RWKeyedLocker_RLock](#RLock) -- [RWKeyedLocker_Lock](#Lock) +- [RLock](#RLock) +- [Lock](#Lock) - [NewTryKeyedLocker](#NewTryKeyedLocker) -- [TryKeyedLocker_TryLock](#TryLock) -- [TryKeyedLocker_Unlock](#Unlock) +- [TryLock](#TryLock) +- [Unlock](#Unlock)
## Documentation ## Channel + ### NewChannel +

Create a Channel pointer instance.

Signature: @@ -59,6 +63,7 @@ import ( type Channel[T any] struct func NewChannel[T any]() *Channel[T] ``` + Example: [Run](https://go.dev/play/p/7aB4KyMMp9A) ```go @@ -83,6 +88,7 @@ func main() { ```go func (c *Channel[T]) Bridge(ctx context.Context, chanStream <-chan <-chan T) <-chan T ``` + Example: [Run](https://go.dev/play/p/qmWSy1NVF-Y) ```go @@ -135,6 +141,7 @@ func main() { ```go func (c *Channel[T]) FanIn(ctx context.Context, channels ...<-chan T) <-chan T ``` + Example: [Run](https://go.dev/play/p/2VYFMexEvTm) ```go @@ -174,6 +181,7 @@ func main() { ```go func (c *Channel[T]) Repeat(ctx context.Context, values ...T) <-chan T ``` + Example: ```go @@ -213,6 +221,7 @@ func main() { ```go func (c *Channel[T]) Generate(ctx context.Context, values ...T) <-chan T ``` + Example: [Run](https://go.dev/play/p/7aB4KyMMp9A) ```go @@ -251,6 +260,7 @@ func main() { ```go func (c *Channel[T]) RepeatFn(ctx context.Context, fn func() T) <-chan T ``` + Example: ```go @@ -293,6 +303,7 @@ func main() { ```go func (c *Channel[T]) Or(channels ...<-chan T) <-chan T ``` + Example: ```go @@ -336,6 +347,7 @@ func main() { ```go func (c *Channel[T]) OrDone(ctx context.Context, channel <-chan T) <-chan T ``` + Example: ```go @@ -374,6 +386,7 @@ func main() { ```go func (c *Channel[T]) Take(ctx context.Context, valueStream <-chan T, number int) <-chan T ``` + Example: ```go @@ -420,6 +433,7 @@ func main() { ```go func (c *Channel[T]) Tee(ctx context.Context, in <-chan T) (<-chan T, <-chan T) ``` + Example: ```go @@ -444,7 +458,7 @@ func main() { fmt.Println(v) fmt.Println(<-ch2) } - + // Output: // 1 // 1 @@ -512,7 +526,7 @@ func main() { } ``` -### KeyedLocker_Do +### Do

Acquires a lock for the specified key and executes the provided function.

@@ -578,6 +592,7 @@ func main() { ```go func NewRWKeyedLocker[K comparable](ttl time.Duration) *RWKeyedLocker[K] ``` + Example:[Run](https://go.dev/play/p/todo) ```go @@ -617,7 +632,7 @@ func main() { } ``` -### RWKeyedLocker_RLock +### RLock

Acquires a read lock for the specified key and executes the provided function.

@@ -626,6 +641,7 @@ func main() { ```go func (l *RWKeyedLocker[K]) RLock(ctx context.Context, key K, fn func()) error ``` + Example:[Run](https://go.dev/play/p/todo) ```go @@ -665,7 +681,7 @@ func main() { } ``` -### RWKeyedLocker_Lock +### Lock

Acquires a write lock for the specified key and executes the provided function.

@@ -674,6 +690,7 @@ func main() { ```go func (l *RWKeyedLocker[K]) Lock(ctx context.Context, key K, fn func()) error ``` + Example:[Run](https://go.dev/play/p/todo) ```go @@ -720,8 +737,9 @@ func main() { Signature: ```go -func NewTryKeyedLocker[K comparable]() *TryKeyedLocker[K] +func NewTryKeyedLocker[K comparable]() *TryKeyedLocker[K] ``` + Example:[Run](https://go.dev/play/p/todo) ```go @@ -753,7 +771,7 @@ func main() { } ``` -### TryKeyedLocker_TryLock +### TryLock

TryLock tries to acquire a lock for the specified key.

@@ -794,7 +812,7 @@ func main() { } ``` -### TryKeyedLocker_Unlock +### Unlock

Unlock releases the lock for the specified key.

@@ -833,4 +851,4 @@ func main() { //Lock acquired //Lock released } -``` \ No newline at end of file +``` diff --git a/docs/en/api/packages/validator.md b/docs/en/api/packages/validator.md index a35b482..093893b 100644 --- a/docs/en/api/packages/validator.md +++ b/docs/en/api/packages/validator.md @@ -826,6 +826,43 @@ func main() { } ``` +### IsAlphaNumeric + +

Check if the string is alphanumeric.

+ +Signature: + +```go +func IsAlphaNumeric(s string) bool +``` + +Example:[Run](https://go.dev/play/p/todo) + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/validator" +) + +func main() { + result1 := validator.IsAlphaNumeric("ABC") + result2 := validator.IsAlphaNumeric("123") + result3 := validator.IsAlphaNumeric("abc123") + result4 := validator.IsAlphaNumeric("abc123@#$") + + fmt.Println(result1) + fmt.Println(result2) + fmt.Println(result3) + fmt.Println(result4) + + // Output: + // true + // true + // true + // false +} +``` + ### IsJSON

Check if the string is valid JSON.

diff --git a/validator/validator.go b/validator/validator.go index dd7b68e..bbc2566 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -182,7 +182,7 @@ func IsJSON(str string) bool { return json.Unmarshal([]byte(str), &js) == nil } -// IsAlphaNumericStr check if the string is alphanumeric. +// IsAlphaNumeric check if the string is alphanumeric. // Play: todo func IsAlphaNumeric(s string) bool { return alphaNumericMatcher.MatchString(s) diff --git a/validator/validator_example_test.go b/validator/validator_example_test.go index c1e736a..088cb86 100644 --- a/validator/validator_example_test.go +++ b/validator/validator_example_test.go @@ -665,3 +665,21 @@ func ExampleIsChinaUnionPay() { // true // false } + +func ExampleIsAlphaNumeric() { + result1 := IsAlphaNumeric("ABC") + result2 := IsAlphaNumeric("123") + result3 := IsAlphaNumeric("abc123") + result4 := IsAlphaNumeric("abc123@#$") + + fmt.Println(result1) + fmt.Println(result2) + fmt.Println(result3) + fmt.Println(result4) + + // Output: + // true + // true + // true + // false +}