mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-14 01:32:27 +08:00
Compare commits
1 Commits
v2.3.4
...
ecafed511c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecafed511c |
40
README.md
40
README.md
@@ -333,7 +333,7 @@ import "github.com/duke-git/lancet/v2/convertor"
|
||||
[[play](https://go.dev/play/p/HwdDPFcza1O)]
|
||||
- **<big>ToBigInt</big>** : 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/todo)]
|
||||
[[play](https://go.dev/play/p/X3itkCxwB_x)]
|
||||
|
||||
<h3 id="cryptor"> 6. Cryptor package is for data encryption and decryption. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -469,10 +469,10 @@ import "github.com/duke-git/lancet/v2/cryptor"
|
||||
[[play](https://go.dev/play/p/zutRHrDqs0X)]
|
||||
- **<big>RsaEncrypt</big>** : encrypt data with ras algorithm.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaEncrypt)]
|
||||
[[play](https://go.dev/play/p/uef0q1fz53I)]
|
||||
[[play](https://go.dev/play/p/7_zo6mrx-eX)]
|
||||
- **<big>RsaDecrypt</big>** : decrypt data with ras algorithm.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaDecrypt)]
|
||||
[[play](https://go.dev/play/p/uef0q1fz53I)]
|
||||
[[play](https://go.dev/play/p/7_zo6mrx-eX)]
|
||||
- **<big>GenerateRsaKeyPair</big>** : creates rsa private and public key.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#GenerateRsaKeyPair)]
|
||||
[[play](https://go.dev/play/p/sSVmkfENKMz)]
|
||||
@@ -484,10 +484,10 @@ import "github.com/duke-git/lancet/v2/cryptor"
|
||||
[[play](https://go.dev/play/p/sSVmkfENKMz)]
|
||||
- **<big>RsaSign</big>** : signs the data with RSA.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaSign)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/qhsbf8BJ6Mf)]
|
||||
- **<big>RsaVerifySign</big>** : verifies the signature of the data with RSA.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaVerifySign)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/qhsbf8BJ6Mf)]
|
||||
|
||||
<h3 id="datetime"> 7. Datetime package supports date and time format and compare. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -633,13 +633,13 @@ import "github.com/duke-git/lancet/v2/datetime"
|
||||
[[play](https://go.dev/play/p/6kHBpAxD9ZC)]
|
||||
- **<big>Min</big>** : returns the earliest time among the given times.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#Min)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/MCIDvHNOGGb)]
|
||||
- **<big>Max</big>** : returns the latest time among the given times.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#Max)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/9m6JMk1LB7-)]
|
||||
- **<big>MaxMin</big>** : returns the latest and earliest time among the given times.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#MaxMin)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/rbW51cDtM_2)]
|
||||
|
||||
<h3 id="datastructure"> 8. Datastructure package contains some common data structure. eg. list, linklist, stack, queue, set, tree, graph. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -777,7 +777,7 @@ import "github.com/duke-git/lancet/v2/fileutil"
|
||||
[[play](https://go.dev/play/p/teMXnCsdSEw)]
|
||||
- **<big>GetExeOrDllVersion</big>** : Get the version of exe or dll file on windows os.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#GetExeOrDllVersion)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/iLRrDBhE38E)]
|
||||
|
||||
<h3 id="formatter"> 10. Formatter contains some functions for data formatting. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1145,16 +1145,16 @@ import "github.com/duke-git/lancet/v2/mathutil"
|
||||
[[play](https://go.dev/play/p/WLxDdGXXYat)]
|
||||
- **<big>Variance</big>** : returns the variance of numbers.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Variance)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/uHuV4YgXf8F)]
|
||||
- **<big>StdDev</big>** : returns the standard deviation of numbers.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#StdDev)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/FkNZDXvHD2l)]
|
||||
- **<big>Permutation</big>** : calculates P(n, k).
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Permutation)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/MgobwH_FOxj)]
|
||||
- **<big>Combination</big>** : calculates C(n, k).
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Combination)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/ENFQRDQUFi9)]
|
||||
|
||||
<h3 id="netutil"> 14. Netutil package contains functions to get net information and send http request. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1317,7 +1317,7 @@ import "github.com/duke-git/lancet/v2/random"
|
||||
[[play](https://go.dev/play/p/68UikN9d6VT)]
|
||||
- **<big>RandNumberOfLength</big>** : generates a random int number of specified length.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/random.md#RandNumberOfLength)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/oyZbuV7bu7b)]
|
||||
|
||||
<h3 id="retry"> 17. Retry package is for executing a function repeatedly until it was successful or canceled by the context. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1613,10 +1613,10 @@ import "github.com/duke-git/lancet/v2/slice"
|
||||
[[play](https://go.dev/play/p/CW3UVNdUZOq)]
|
||||
- **<big>JoinFunc</big>** : joins the slice elements into a single string with the given separator.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#JoinFunc)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/55ib3SB5fM2)]
|
||||
- **<big>ConcatBy</big>** : concats the elements of a slice into a single value using the provided separator and connector function.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#ConcatBy)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/6QcUpcY4UMW)]
|
||||
|
||||
<h3 id="stream"> 19. Stream package implements a sequence of elements supporting sequential and operations. this package is an experiment to explore if stream in go can work as the way java does. its function is very limited. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1709,10 +1709,10 @@ import "github.com/duke-git/lancet/v2/stream"
|
||||
[[play](https://go.dev/play/p/jI6_iZZuVFE)]
|
||||
- **<big>IndexOf</big>** : returns the index of the first occurrence of the specified element in this stream.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#IndexOf)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/tBV5Nc-XDX2)]
|
||||
- **<big>LastIndexOf</big>** : returns the index of the last occurrence of the specified element in this stream.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#LastIndexOf)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/CjeoNw2eac_G)]
|
||||
|
||||
<h3 id="structs"> 20. Structs package provides several high level functions to manipulate struct, tag, and field. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1896,7 +1896,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
||||
[[play](https://go.dev/play/p/JZiu0RXpgN-)]
|
||||
- **<big>ExtractContent</big>** : extracts the content between the start and end strings in the source string.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#ExtractContent)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/Ay9UIk7Rum9)]
|
||||
|
||||
|
||||
<h3 id="system"> 22. System package contain some functions about os, runtime, shell command. <a href="#index">index</a></h3>
|
||||
@@ -2249,7 +2249,7 @@ import "github.com/duke-git/lancet/v2/xerror"
|
||||
[[play](https://go.dev/play/p/acyZVkNZEeW)]
|
||||
- **<big>TryCatch</big>** : 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/todo)]
|
||||
[[play](https://go.dev/play/p/D5Mdb0mRj0P)]
|
||||
|
||||
## How to Contribute
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ import "github.com/duke-git/lancet/v2/convertor"
|
||||
[[play](https://go.dev/play/p/HwdDPFcza1O)]
|
||||
- **<big>ToBigInt</big>** : 将整数转为*big.Int。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToBigInt)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/X3itkCxwB_x)]
|
||||
|
||||
<h3 id="cryptor"> 6. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -470,10 +470,10 @@ import "github.com/duke-git/lancet/v2/cryptor"
|
||||
[[play](https://go.dev/play/p/zutRHrDqs0X)]
|
||||
- **<big>RsaEncrypt</big>** : 用公钥文件 ras 加密数据。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaEncrypt)]
|
||||
[[play](https://go.dev/play/p/uef0q1fz53I)]
|
||||
[[play](https://go.dev/play/p/7_zo6mrx-eX)]
|
||||
- **<big>RsaDecrypt</big>** : 用私钥文件 rsa 解密数据。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaDecrypt)]
|
||||
[[play](https://go.dev/play/p/uef0q1fz53I)]
|
||||
[[play](https://go.dev/play/p/7_zo6mrx-eX)]
|
||||
- **<big>GenerateRsaKeyPair</big>** : 创建rsa公钥私钥和key。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#GenerateRsaKeyPair)]
|
||||
[[play](https://go.dev/play/p/sSVmkfENKMz)]
|
||||
@@ -485,10 +485,10 @@ import "github.com/duke-git/lancet/v2/cryptor"
|
||||
[[play](https://go.dev/play/p/sSVmkfENKMz)]
|
||||
- **<big>RsaSign</big>** : 应用RSA算法签名数据。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaSign)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/qhsbf8BJ6Mf)]
|
||||
- **<big>RsaVerifySign</big>** : 验证数据的签名是否符合RSA算法。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaVerifySign)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/qhsbf8BJ6Mf)]
|
||||
|
||||
<h3 id="datetime"> 7. datetime日期时间处理包,格式化日期,比较日期。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -635,13 +635,13 @@ import "github.com/duke-git/lancet/v2/datetime"
|
||||
[[play](https://go.dev/play/p/6kHBpAxD9ZC)]
|
||||
- **<big>Min</big>** : 返回最早时间。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#Min)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/MCIDvHNOGGb)]
|
||||
- **<big>Max</big>** : 返回最晚时间。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#Max)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/9m6JMk1LB7-)]
|
||||
- **<big>MaxMin</big>** : 返回最早和最晚时间。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#MaxMin)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/rbW51cDtM_2)]
|
||||
|
||||
|
||||
<h3 id="datastructure"> 8. datastructure 包含一些普通的数据结构实现。例如:list, linklist, stack, queue, set, tree, graph。 <a href="#index">回到目录</a></h3>
|
||||
@@ -776,7 +776,7 @@ import "github.com/duke-git/lancet/v2/fileutil"
|
||||
[[play](https://go.dev/play/p/teMXnCsdSEw)]
|
||||
- **<big>GetExeOrDllVersion</big>** : 返回exe,dll文件版本号(仅Window平台)。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#GetExeOrDllVersion)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/iLRrDBhE38E)]
|
||||
|
||||
|
||||
<h3 id="formatter"> 10. formatter 格式化器包含一些数据格式化处理方法。 <a href="#index">回到目录</a></h3>
|
||||
@@ -1145,16 +1145,16 @@ import "github.com/duke-git/lancet/v2/mathutil"
|
||||
[[play](https://go.dev/play/p/WLxDdGXXYat)]
|
||||
- **<big>Variance</big>** : 计算方差。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Variance)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/uHuV4YgXf8F)]
|
||||
- **<big>StdDev</big>** : 计算标准差。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#StdDev)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/FkNZDXvHD2l)]
|
||||
- **<big>Permutation</big>** : 计算排列数P(n, k)。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Permutation)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/MgobwH_FOxj)]
|
||||
- **<big>Combination</big>** : 计算组合数C(n, k)。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Combination)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/ENFQRDQUFi9)]
|
||||
|
||||
<h3 id="netutil"> 14. netutil 网络包支持获取 ip 地址,发送 http 请求。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -1317,7 +1317,7 @@ import "github.com/duke-git/lancet/v2/random"
|
||||
[[play](https://go.dev/play/p/68UikN9d6VT)]
|
||||
- **<big>RandNumberOfLength</big>** : 生成指定长度的随机数。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandNumberOfLength)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/oyZbuV7bu7b)]
|
||||
|
||||
<h3 id="retry"> 17. retry 重试执行函数直到函数运行成功或被 context cancel。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -1610,10 +1610,10 @@ import "github.com/duke-git/lancet/v2/slice"
|
||||
[[play](https://go.dev/play/p/CW3UVNdUZOq)]
|
||||
- **<big>JoinFunc</big>** : 将切片元素用给定的分隔符连接成一个单一的字符串。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#JoinFunc)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/55ib3SB5fM2)]
|
||||
- **<big>ConcatBy</big>** : 将切片中的元素连接成一个值,使用指定的分隔符和连接器函数。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#ConcatBy)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/6QcUpcY4UMW)]
|
||||
|
||||
<h3 id="stream"> 19. stream 流,该包仅验证简单的 stream 实现,功能有限。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -1706,10 +1706,10 @@ import "github.com/duke-git/lancet/v2/stream"
|
||||
[[play](https://go.dev/play/p/jI6_iZZuVFE)]
|
||||
- **<big>IndexOf</big>** : 返回在stream中找到值的第一个匹配项的索引,如果找不到值,则返回-1。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#IndexOf)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/tBV5Nc-XDX2)]
|
||||
- **<big>LastIndexOf</big>** : 返回在stream中找到值的最后一个匹配项的索引,如果找不到值,则返回-1。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#LastIndexOf)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/CjeoNw2eac_G)]
|
||||
|
||||
<h3 id="structs"> 20. structs 提供操作 struct, tag, field 的相关函数。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -1896,7 +1896,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
||||
[[play](https://go.dev/play/p/JZiu0RXpgN-)]
|
||||
- **<big>ExtractContent</big>** : 提取两个标记之间的内容。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#ExtractContent)]
|
||||
[[play](https://go.dev/play/p/todo)]
|
||||
[[play](https://go.dev/play/p/Ay9UIk7Rum9)]
|
||||
|
||||
<h3 id="system"> 22. system 包含 os, runtime, shell command 的相关函数。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -2249,7 +2249,7 @@ import "github.com/duke-git/lancet/v2/xerror"
|
||||
[[play](https://go.dev/play/p/acyZVkNZEeW)]
|
||||
- **<big>TryCatch</big>** : 简单实现的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/todo)]
|
||||
[[play](https://go.dev/play/p/D5Mdb0mRj0P)]
|
||||
|
||||
## 如何贡献代码
|
||||
|
||||
|
||||
@@ -143,12 +143,8 @@ func ToString(value any) string {
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
|
||||
// todo: maybe we should't supprt other type conversion
|
||||
// v := reflect.ValueOf(value)
|
||||
// log.Panicf("Unsupported data type: %s ", v.String())
|
||||
// return ""
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,7 +482,7 @@ func ToRawUrlBase64(value any) string {
|
||||
}
|
||||
|
||||
// ToBigInt converts an integer of any supported type (int, int64, uint64, etc.) to *big.Int
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/X3itkCxwB_x
|
||||
func ToBigInt[T any](v T) (*big.Int, error) {
|
||||
result := new(big.Int)
|
||||
|
||||
|
||||
@@ -565,7 +565,7 @@ func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error {
|
||||
}
|
||||
|
||||
// RsaEncrypt encrypt data with ras algorithm.
|
||||
// Play: https://go.dev/play/p/rDqTT01SPkZ
|
||||
// Play: https://go.dev/play/p/7_zo6mrx-eX
|
||||
func RsaEncrypt(data []byte, pubKeyFileName string) []byte {
|
||||
file, err := os.Open(pubKeyFileName)
|
||||
if err != nil {
|
||||
@@ -600,7 +600,7 @@ func RsaEncrypt(data []byte, pubKeyFileName string) []byte {
|
||||
}
|
||||
|
||||
// RsaDecrypt decrypt data with ras algorithm.
|
||||
// Play: https://go.dev/play/p/rDqTT01SPkZ
|
||||
// Play: https://go.dev/play/p/7_zo6mrx-eX
|
||||
func RsaDecrypt(data []byte, privateKeyFileName string) []byte {
|
||||
file, err := os.Open(privateKeyFileName)
|
||||
if err != nil {
|
||||
@@ -663,7 +663,7 @@ func RsaDecryptOAEP(ciphertext []byte, label []byte, key rsa.PrivateKey) ([]byte
|
||||
}
|
||||
|
||||
// RsaSign signs the data with RSA.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/qhsbf8BJ6Mf
|
||||
func RsaSign(hash crypto.Hash, data []byte, privateKeyFileName string) ([]byte, error) {
|
||||
privateKey, err := loadRasPrivateKey(privateKeyFileName)
|
||||
if err != nil {
|
||||
@@ -679,7 +679,7 @@ func RsaSign(hash crypto.Hash, data []byte, privateKeyFileName string) ([]byte,
|
||||
}
|
||||
|
||||
// RsaVerifySign verifies the signature of the data with RSA.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/qhsbf8BJ6Mf
|
||||
func RsaVerifySign(hash crypto.Hash, data, signature []byte, pubKeyFileName string) error {
|
||||
publicKey, err := loadRsaPublicKey(pubKeyFileName)
|
||||
if err != nil {
|
||||
@@ -712,7 +712,6 @@ func loadRsaPublicKey(filename string) (*rsa.PublicKey, error) {
|
||||
if blockType == "RSA PUBLIC KEY" {
|
||||
pubKey, err = x509.ParsePKCS1PublicKey(block.Bytes)
|
||||
if err != nil {
|
||||
// todo: here should be a bug, should return nil, err
|
||||
key, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
-----BEGIN rsa private key-----
|
||||
MIIJJwIBAAKCAgEAwGdN8KE2NTK41cVN7i6mZZS5J86gjNs0LJDHylb2GG+K4O8s
|
||||
fq98EMKMJ2xGnKoVRJXucVohr5Eiuf5zgxQe9mpYDyDQ0vnpBkoNkfzJNZQvcQFa
|
||||
IllUeH+eN4hSBhMegPspCr2BcmC/m/N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6HZxXPWRsgs1YUuxed2L
|
||||
aFFcXT403kxYIIyngCPWbeZHNrqD23I6KBfJi+/mBVl+/win8O5wmWmX5UDQLohE
|
||||
Y2bp8nmOqIk3yD+BeCIMQOsCqoWq+Nl0PtEueRhdF4qmvl65KPGPg5d5OzzZHRcG
|
||||
rHov/p7TM7bCKTGRDqjlYrUgeUDFD7h0wMgBYSvFE2uk7GMo0/aJwc9wPg==
|
||||
-----END rsa private key-----
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
-----BEGIN rsa public key-----
|
||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwGdN8KE2NTK41cVN7i6m
|
||||
ZZS5J86gjNs0LJDHylb2GG+K4O8sfq98EMKMJ2xGnKoVRJXucVohr5Eiuf5zgxQe
|
||||
9mpYDyDQ0vnpBkoNkfzJNZQvcQFaIllUeH+eN4hSBhMegPspCr2BcmC/m/N40+Pj
|
||||
BMDaHSzeNE2SyIuyflLC7GhQvHnkcQXkqJVNC1yesV7zYKDV/xYPI0NxN0kE+4eR
|
||||
650A77jso4gloRUek0cpU4ztpe6Zz4za7AEKHmZO8pVHpQJihbNMhItbo6BcgeOF
|
||||
WImXyJfcbCtu1ayciaJ0Q45Z1btuF2wFwQjwZGt7DAvbzYwMBBiTpGxig/8kzibm
|
||||
7bL1Td7huW6Knqbfh4/v+2m+2aNK1u0TfncFUr17wDDfeVj/xeNOSbPu2X/AppjV
|
||||
X0rxmvWN+AByFfAuw7/kqMK7QZlA+5nNjmOojvryGOSu1he4PUnhRyJ7jofOIrLZ
|
||||
9YYBXpRiY/WB8t+xWIlaoPXFmsOxSgMwzQFGMlnSFy7nK9T4znE0QFknOQNbELPE
|
||||
B4UGLOEa5Tg6YD2ORDDSqCzMRdkE1kAgoMRC9DkRXE45KEcQlhMX9Pahwx3mPS4l
|
||||
MWABVudiEWyhGaR279OWjezqvtoLLBJ5GD9QL1XqaqCaJjp+qsHmX8re+MTA3ZJu
|
||||
yUtRoPXPsKCe2nZ6Ma87DlUCAwEAAQ==
|
||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA00EXXa5qy/g4DLIedOhb
|
||||
oYGZoS/S9B7qy5nHbxum6bt0Y+U5DheGNielHwDz3k2WJYk75KZI9eoDdC4d8C9d
|
||||
gWuf1FQmIFu9OtjGiPt+WdYpKJUD1OXNiipx44xDsGYc4daBfLlNujhYQjWVfh7q
|
||||
y62jXbPfJJYC9VFNkg9T36ejzjpFiXSM678rdRq9lIcisY75ez1z6ksdnv8GetNJ
|
||||
pC7W/4Ij0vNndi9R2hlclV5+IxGu7nB5us13IwJSTnyKokS6Mjh/sLiHvF+7OUWR
|
||||
WlTs2qvBuTTk3F7zrzOHvBs+6b/nUBqMBKqhzTcjK2njg9DuQj3IhmyHgcYKWwC2
|
||||
KucsuUW/xbFQCceemHGzZ2kceDHYUNUg4UncWXKF466uS93y4fdUeFTe9ojyearY
|
||||
w9Ip/9CA9ERq04h44KJA3HGVpCPxrk3pqM3gfzAR7T7gzZQjotPwuGrGT84jcOvc
|
||||
CYRcJnIm/5xQaIT9N1iEkyDZaH0rXiFttn2zsNOTYuASj5Z+Y4AfH3+dBc1ebWjZ
|
||||
UIurgq3JJUmplArD6k99Y3qH9nHArrRMRC7iyEsVwOWYMcadkF6l+pVYAXnxy6nA
|
||||
NMpwM5DOiKY4jhZ5QMyp1E4oQtGNlrV/mqdOHXM3Gb5Vclw0JiQ1LMOihoURliuh
|
||||
wxj4u6AJMnILHBGQQ5P3NQsCAwEAAQ==
|
||||
-----END rsa public key-----
|
||||
|
||||
@@ -445,7 +445,7 @@ func GenerateDatetimesBetween(start, end time.Time, layout string, interval stri
|
||||
}
|
||||
|
||||
// Min returns the earliest time among the given times.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/MCIDvHNOGGb
|
||||
func Min(t1 time.Time, times ...time.Time) time.Time {
|
||||
minTime := t1
|
||||
|
||||
@@ -459,7 +459,7 @@ func Min(t1 time.Time, times ...time.Time) time.Time {
|
||||
}
|
||||
|
||||
// Max returns the latest time among the given times.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/9m6JMk1LB7-
|
||||
func Max(t1 time.Time, times ...time.Time) time.Time {
|
||||
maxTime := t1
|
||||
|
||||
@@ -473,7 +473,7 @@ func Max(t1 time.Time, times ...time.Time) time.Time {
|
||||
}
|
||||
|
||||
// MaxMin returns the latest and earliest time among the given times.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/rbW51cDtM_2
|
||||
func MaxMin(t1 time.Time, times ...time.Time) (maxTime time.Time, minTime time.Time) {
|
||||
maxTime = t1
|
||||
minTime = t1
|
||||
|
||||
@@ -1155,7 +1155,7 @@ func main() {
|
||||
|
||||
<p>将整数值转换为bigInt。</p>
|
||||
|
||||
<b>函数签名:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>函数签名:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/X3itkCxwB_x)</span></b>
|
||||
|
||||
```go
|
||||
func ToBigInt[T any](v T) (*big.Int, error)
|
||||
|
||||
@@ -1436,7 +1436,7 @@ func main() {
|
||||
func RsaEncrypt(data []byte, pubKeyFileName string) []byte
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/7_zo6mrx-eX)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1473,7 +1473,7 @@ func main() {
|
||||
func RsaDecrypt(data []byte, privateKeyFileName string) []byte
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/7_zo6mrx-eX)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1621,7 +1621,7 @@ func main() {
|
||||
func RsaSign(hash crypto.Hash, data []byte, privateKeyFileName string) ([]byte, error)
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qhsbf8BJ6Mf)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1638,12 +1638,12 @@ func main() {
|
||||
privateKey := "./rsa_private.pem"
|
||||
publicKey := "./rsa_public.pem"
|
||||
|
||||
signature, err := RsaSign(hash, data, privateKey)
|
||||
signature, err := cryptor.RsaSign(hash, data, privateKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = RsaVerifySign(hash, data, signature, publicKey)
|
||||
err = cryptor.RsaVerifySign(hash, data, signature, publicKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -1660,7 +1660,7 @@ func main() {
|
||||
func RsaVerifySign(hash crypto.Hash, data, signature []byte, pubKeyFileName string) error
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qhsbf8BJ6Mf)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1677,12 +1677,12 @@ func main() {
|
||||
privateKey := "./rsa_private.pem"
|
||||
publicKey := "./rsa_public.pem"
|
||||
|
||||
signature, err := RsaSign(hash, data, privateKey)
|
||||
signature, err := cryptor.RsaSign(hash, data, privateKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = RsaVerifySign(hash, data, signature, publicKey)
|
||||
err = cryptor.RsaVerifySign(hash, data, signature, publicKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1585,7 +1585,7 @@ func main() {
|
||||
func Min(t1 time.Time, times ...time.Time) time.Time
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/MCIDvHNOGGb)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1615,7 +1615,7 @@ func main() {
|
||||
func Max(t1 time.Time, times ...time.Time) time.Time
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9m6JMk1LB7-)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1645,7 +1645,7 @@ func main() {
|
||||
func MaxMin(t1 time.Time, times ...time.Time) (maxTime time.Time, minTime time.Time)
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/rbW51cDtM_2)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1088,7 +1088,7 @@ func main() {
|
||||
func GetExeOrDllVersion(filePath string) (string, error)
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/iLRrDBhE38E)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1178,7 +1178,7 @@ func main() {
|
||||
func Variance[T constraints.Float | constraints.Integer](numbers []T) float64
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[示例](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[示例](https://go.dev/play/p/uHuV4YgXf8F)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1211,7 +1211,7 @@ func main() {
|
||||
func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/FkNZDXvHD2l)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1222,8 +1222,8 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := mathutil.T运行cRound(mathutil.StdDev([]int{1, 2, 3, 4, 5}), 2)
|
||||
result2 := mathutil.T运行cRound(mathutil.StdDev([]float64{1.1, 2.2, 3.3, 4.4, 5.5}), 2)
|
||||
result1 := mathutil.TruncRound(mathutil.StdDev([]int{1, 2, 3, 4, 5}), 2)
|
||||
result2 := mathutil.TruncRound(mathutil.StdDev([]float64{1.1, 2.2, 3.3, 4.4, 5.5}), 2)
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
@@ -1244,7 +1244,7 @@ func main() {
|
||||
func Permutation(n, k uint) uint
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/MgobwH_FOxj)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1277,7 +1277,7 @@ func main() {
|
||||
func Combination(n, k uint) uint
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ENFQRDQUFi9)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -534,7 +534,7 @@ func main() {
|
||||
func RandNumberOfLength(len int) int
|
||||
```
|
||||
|
||||
<b>实例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>实例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/oyZbuV7bu7b)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -2999,7 +2999,7 @@ func main() {
|
||||
func JoinFunc[T any](slice []T, sep string, transform func(T) T) string
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/55ib3SB5fM2)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -3029,7 +3029,7 @@ func main() {
|
||||
func ConcatBy[T any](slice []T, sep T, connector func(T, T) T) T
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/6QcUpcY4UMW)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -951,7 +951,7 @@ func main() {
|
||||
func (s Stream[T]) IndexOf(target T, equal func(a, b T) bool) int
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tBV5Nc-XDX2)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -984,7 +984,7 @@ func main() {
|
||||
func (s Stream[T]) LastIndexOf(target T, equal func(a, b T) bool) int
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/CjeoNw2eac_G)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -1741,7 +1741,7 @@ func main() {
|
||||
func ExtractContent(s, start, end string) []string
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Ay9UIk7Rum9)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -509,7 +509,7 @@ func (tc *TryCatch) Finally(finallyFunc func(ctx context.Context)) *TryCatch
|
||||
func (tc *TryCatch) Do()
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](todo)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/D5Mdb0mRj0P)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -529,8 +529,6 @@ func main() {
|
||||
return errors.New("error in try block")
|
||||
}).Catch(func(ctx context.Context, err error) {
|
||||
calledCatch = true
|
||||
// Error in try block at /path/xxx.go:{line_number} - Cause: error message
|
||||
// fmt.Println(err.Error())
|
||||
}).Finally(func(ctx context.Context) {
|
||||
calledFinally = true
|
||||
}).Do()
|
||||
|
||||
@@ -1123,7 +1123,7 @@ func main() {
|
||||
|
||||
<p>Converts an integer of any supported type (int, int64, uint64, etc.) to *big.Int</p>
|
||||
|
||||
<b>Signature:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Signature:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/X3itkCxwB_x)</span></b>
|
||||
|
||||
```go
|
||||
func ToBigInt[T any](v T) (*big.Int, error)
|
||||
|
||||
@@ -1435,7 +1435,7 @@ func main() {
|
||||
func RsaEncrypt(data []byte, pubKeyFileName string) []byte
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/7_zo6mrx-eX)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1472,7 +1472,7 @@ func main() {
|
||||
func RsaDecrypt(data []byte, privateKeyFileName string) []byte
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/7_zo6mrx-eX)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1620,7 +1620,7 @@ func main() {
|
||||
func RsaSign(hash crypto.Hash, data []byte, privateKeyFileName string) ([]byte, error)
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qhsbf8BJ6Mf)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1659,7 +1659,7 @@ func main() {
|
||||
func RsaVerifySign(hash crypto.Hash, data, signature []byte, pubKeyFileName string) error
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qhsbf8BJ6Mf)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1586,7 +1586,7 @@ func main() {
|
||||
func Min(t1 time.Time, times ...time.Time) time.Time
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/MCIDvHNOGGb)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1616,7 +1616,7 @@ func main() {
|
||||
func Max(t1 time.Time, times ...time.Time) time.Time
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9m6JMk1LB7-)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1646,7 +1646,7 @@ func main() {
|
||||
func MaxMin(t1 time.Time, times ...time.Time) (maxTime time.Time, minTime time.Time)
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/rbW51cDtM_2)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1087,7 +1087,7 @@ func main() {
|
||||
func GetExeOrDllVersion(filePath string) (string, error)
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/iLRrDBhE38E)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -1177,7 +1177,7 @@ func main() {
|
||||
func Variance[T constraints.Float | constraints.Integer](numbers []T) float64
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uHuV4YgXf8F)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1210,7 +1210,7 @@ func main() {
|
||||
func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/FkNZDXvHD2l)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1243,7 +1243,7 @@ func main() {
|
||||
func Permutation(n, k uint) uint
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/MgobwH_FOxj)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
@@ -1276,7 +1276,7 @@ func main() {
|
||||
func Combination(n, k uint) uint
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ENFQRDQUFi9)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -536,7 +536,7 @@ func main() {
|
||||
func RandNumberOfLength(len int) int
|
||||
```
|
||||
|
||||
<b>Signature:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Signature:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/oyZbuV7bu7b)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -2995,7 +2995,7 @@ func main() {
|
||||
func JoinFunc[T any](slice []T, sep string, transform func(T) T) string
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/55ib3SB5fM2)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -3025,7 +3025,7 @@ func main() {
|
||||
func ConcatBy[T any](slice []T, sep T, connector func(T, T) T) T
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/6QcUpcY4UMW)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -950,7 +950,7 @@ func main() {
|
||||
func (s Stream[T]) IndexOf(target T, equal func(a, b T) bool) int
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tBV5Nc-XDX2)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -983,7 +983,7 @@ func main() {
|
||||
func (s Stream[T]) LastIndexOf(target T, equal func(a, b T) bool) int
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/CjeoNw2eac_G)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -1743,7 +1743,7 @@ func main() {
|
||||
func ExtractContent(s, start, end string) []string
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Ay9UIk7Rum9)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
|
||||
@@ -507,7 +507,7 @@ func (tc *TryCatch) Finally(finallyFunc func(ctx context.Context)) *TryCatch
|
||||
func (tc *TryCatch) Do()
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/D5Mdb0mRj0P)</span></b>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@@ -26,7 +26,7 @@ type tagVS_FIXEDFILEINFO struct {
|
||||
}
|
||||
|
||||
// GetExeOrDllVersion get the version of exe or dll file on windows.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/iLRrDBhE38E
|
||||
func GetExeOrDllVersion(filePath string) (string, error) {
|
||||
// 加载系统dll
|
||||
versionDLL := syscall.NewLazyDLL("version.dll")
|
||||
|
||||
@@ -400,7 +400,7 @@ func Div[T constraints.Float | constraints.Integer](x T, y T) float64 {
|
||||
}
|
||||
|
||||
// Variance returns the variance of numbers.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/uHuV4YgXf8F
|
||||
func Variance[T constraints.Float | constraints.Integer](numbers []T) float64 {
|
||||
n := len(numbers)
|
||||
if n == 0 {
|
||||
@@ -418,13 +418,13 @@ func Variance[T constraints.Float | constraints.Integer](numbers []T) float64 {
|
||||
}
|
||||
|
||||
// StdDev returns the standard deviation of numbers.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/FkNZDXvHD2l
|
||||
func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64 {
|
||||
return math.Sqrt(Variance(numbers))
|
||||
}
|
||||
|
||||
// Permutation calculate P(n, k).
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/MgobwH_FOxj
|
||||
func Permutation(n, k uint) uint {
|
||||
if n < k {
|
||||
return 0
|
||||
@@ -437,7 +437,7 @@ func Permutation(n, k uint) uint {
|
||||
}
|
||||
|
||||
// Combination calculate C(n, k).
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/ENFQRDQUFi9
|
||||
func Combination(n, k uint) uint {
|
||||
if n < k {
|
||||
return 0
|
||||
|
||||
@@ -335,7 +335,7 @@ func UUIdV4() (string, error) {
|
||||
}
|
||||
|
||||
// RandNumberOfLength 生成一个长度为len的随机数
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/oyZbuV7bu7b
|
||||
func RandNumberOfLength(len int) int {
|
||||
m := int(math.Pow10(len) - 1)
|
||||
i := int(math.Pow10(len - 1))
|
||||
|
||||
@@ -1415,7 +1415,7 @@ func Frequency[T comparable](slice []T) map[T]int {
|
||||
}
|
||||
|
||||
// JoinFunc joins the slice elements into a single string with the given separator.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/55ib3SB5fM2
|
||||
func JoinFunc[T any](slice []T, sep string, transform func(T) T) string {
|
||||
var buf strings.Builder
|
||||
for i, v := range slice {
|
||||
@@ -1428,7 +1428,7 @@ func JoinFunc[T any](slice []T, sep string, transform func(T) T) string {
|
||||
}
|
||||
|
||||
// ConcatBy concats the elements of a slice into a single value using the provided separator and connector function.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/6QcUpcY4UMW
|
||||
func ConcatBy[T any](slice []T, sep T, connector func(T, T) T) T {
|
||||
var result T
|
||||
|
||||
|
||||
@@ -130,7 +130,6 @@ func (s Stream[T]) Distinct() Stream[T] {
|
||||
distinct := map[string]bool{}
|
||||
|
||||
for _, v := range s.source {
|
||||
// todo: performance issue
|
||||
k := hashKey(v)
|
||||
if _, ok := distinct[k]; !ok {
|
||||
distinct[k] = true
|
||||
@@ -395,6 +394,7 @@ func (s Stream[T]) Min(less func(a, b T) bool) (T, bool) {
|
||||
}
|
||||
|
||||
// IndexOf returns the index of the first occurrence of the specified element in this stream, or -1 if this stream does not contain the element.
|
||||
// Play: https://go.dev/play/p/tBV5Nc-XDX2
|
||||
func (s Stream[T]) IndexOf(target T, equal func(a, b T) bool) int {
|
||||
for i, v := range s.source {
|
||||
if equal(v, target) {
|
||||
@@ -405,6 +405,7 @@ func (s Stream[T]) IndexOf(target T, equal func(a, b T) bool) int {
|
||||
}
|
||||
|
||||
// LastIndexOf returns the index of the last occurrence of the specified element in this stream, or -1 if this stream does not contain the element.
|
||||
// Play: https://go.dev/play/p/CjeoNw2eac_G
|
||||
func (s Stream[T]) LastIndexOf(target T, equal func(a, b T) bool) int {
|
||||
for i := len(s.source) - 1; i >= 0; i-- {
|
||||
if equal(s.source[i], target) {
|
||||
|
||||
@@ -737,7 +737,7 @@ func RegexMatchAllGroups(pattern, str string) [][]string {
|
||||
}
|
||||
|
||||
// ExtractContent extracts the content between the start and end strings in the source string.
|
||||
// Play: todo
|
||||
// Play: https://go.dev/play/p/Ay9UIk7Rum9
|
||||
func ExtractContent(s, start, end string) []string {
|
||||
result := []string{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user