1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
dudaodong ecafed511c doc: add play ground demo for v2.3.4 2024-12-04 14:25:51 +08:00
dudaodong 4ffff0e3f3 update pem file 2024-12-04 11:26:49 +08:00
dudaodong 8ebb8a028e doc: update doc for v2.3.4 2024-12-04 11:24:53 +08:00
38 changed files with 338 additions and 181 deletions
+62 -9
View File
@@ -4,7 +4,7 @@
<br/> <br/>
![Go version](https://img.shields.io/badge/go-%3E%3Dv1.18-9cf) ![Go version](https://img.shields.io/badge/go-%3E%3Dv1.18-9cf)
[![Release](https://img.shields.io/badge/release-2.3.3-green.svg)](https://github.com/duke-git/lancet/releases) [![Release](https://img.shields.io/badge/release-2.3.4-green.svg)](https://github.com/duke-git/lancet/releases)
[![GoDoc](https://godoc.org/github.com/duke-git/lancet/v2?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet/v2) [![GoDoc](https://godoc.org/github.com/duke-git/lancet/v2?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet/v2)
[![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet/v2)](https://goreportcard.com/report/github.com/duke-git/lancet/v2) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet/v2)](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
[![test](https://github.com/duke-git/lancet/actions/workflows/codecov.yml/badge.svg?branch=main&event=push)](https://github.com/duke-git/lancet/actions/workflows/codecov.yml) [![test](https://github.com/duke-git/lancet/actions/workflows/codecov.yml/badge.svg?branch=main&event=push)](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
@@ -39,7 +39,7 @@
go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x
``` ```
2. <b>For users who use version below go1.18, you should install v1.x.x. The latest of v1.x.x is v1.4.4. </b> 2. <b>For users who use version below go1.18, you should install v1.x.x. The latest of v1.x.x is v1.4.5. </b>
```go ```go
go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x
@@ -321,12 +321,19 @@ import "github.com/duke-git/lancet/v2/convertor"
[[play](https://go.dev/play/p/OphmHCN_9u8)] [[play](https://go.dev/play/p/OphmHCN_9u8)]
- **<big>ToStdBase64</big>** : converts a value to a string encoded in standard Base64. - **<big>ToStdBase64</big>** : converts a value to a string encoded in standard Base64.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToStdBase64)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToStdBase64)]
[[play](https://go.dev/play/p/_fLJqJD3NMo)]
- **<big>ToUrlBase64</big>** : converts a value to a string encoded in url Base64. - **<big>ToUrlBase64</big>** : converts a value to a string encoded in url Base64.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToUrlBase64)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToUrlBase64)]
[[play](https://go.dev/play/p/C_d0GlvEeUR)]
- **<big>ToRawStdBase64</big>** : converts a value to a string encoded in raw standard Base64. - **<big>ToRawStdBase64</big>** : converts a value to a string encoded in raw standard Base64.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToRawStdBase64)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToRawStdBase64)]
[[play](https://go.dev/play/p/wSAr3sfkDcv)]
- **<big>ToRawUrlBase64</big>** : converts a value to a string encoded in raw url Base64. - **<big>ToRawUrlBase64</big>** : 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)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToRawUrlBase64)]
[[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/X3itkCxwB_x)]
<h3 id="cryptor"> 6. Cryptor package is for data encryption and decryption.&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="cryptor"> 6. Cryptor package is for data encryption and decryption.&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -462,10 +469,10 @@ import "github.com/duke-git/lancet/v2/cryptor"
[[play](https://go.dev/play/p/zutRHrDqs0X)] [[play](https://go.dev/play/p/zutRHrDqs0X)]
- **<big>RsaEncrypt</big>** : encrypt data with ras algorithm. - **<big>RsaEncrypt</big>** : encrypt data with ras algorithm.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaEncrypt)] [[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. - **<big>RsaDecrypt</big>** : decrypt data with ras algorithm.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaDecrypt)] [[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. - **<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)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#GenerateRsaKeyPair)]
[[play](https://go.dev/play/p/sSVmkfENKMz)] [[play](https://go.dev/play/p/sSVmkfENKMz)]
@@ -475,7 +482,12 @@ import "github.com/duke-git/lancet/v2/cryptor"
- **<big>RsaDecryptOAEP</big>** : decrypts the data with RSA-OAEP - **<big>RsaDecryptOAEP</big>** : decrypts the data with RSA-OAEP
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaDecryptOAEP)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/cryptor.md#RsaDecryptOAEP)]
[[play](https://go.dev/play/p/sSVmkfENKMz)] [[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/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/qhsbf8BJ6Mf)]
<h3 id="datetime"> 7. Datetime package supports date and time format and compare. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="datetime"> 7. Datetime package supports date and time format and compare. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -619,7 +631,15 @@ import "github.com/duke-git/lancet/v2/datetime"
- **<big>GenerateDatetimesBetween</big>** : returns a slice of strings between two times. - **<big>GenerateDatetimesBetween</big>** : returns a slice of strings between two times.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#GenerateDatetimesBetween)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#GenerateDatetimesBetween)]
[[play](https://go.dev/play/p/6kHBpAxD9ZC)] [[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/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/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/rbW51cDtM_2)]
<h3 id="datastructure"> 8. Datastructure package contains some common data structure. eg. list, linklist, stack, queue, set, tree, graph. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="datastructure"> 8. Datastructure package contains some common data structure. eg. list, linklist, stack, queue, set, tree, graph. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -755,6 +775,9 @@ import "github.com/duke-git/lancet/v2/fileutil"
- **<big>ParallelChunkRead</big>** : reads the file in parallel and send each chunk of lines to the specified channel. - **<big>ParallelChunkRead</big>** : reads the file in parallel and send each chunk of lines to the specified channel.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#ParallelChunkRead)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#ParallelChunkRead)]
[[play](https://go.dev/play/p/teMXnCsdSEw)] [[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/iLRrDBhE38E)]
<h3 id="formatter"> 10. Formatter contains some functions for data formatting. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="formatter"> 10. Formatter contains some functions for data formatting. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -1120,7 +1143,18 @@ import "github.com/duke-git/lancet/v2/mathutil"
- **<big>Div</big>** : returns the result of x divided by y. - **<big>Div</big>** : returns the result of x divided by y.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Div)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Div)]
[[play](https://go.dev/play/p/WLxDdGXXYat)] [[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/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/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/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/ENFQRDQUFi9)]
<h3 id="netutil"> 14. Netutil package contains functions to get net information and send http request. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="netutil"> 14. Netutil package contains functions to get net information and send http request. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -1281,7 +1315,9 @@ import "github.com/duke-git/lancet/v2/random"
- **<big>RandSliceFromGivenSlice</big>** : generate a random slice of length num from given slice. - **<big>RandSliceFromGivenSlice</big>** : generate a random slice of length num from given slice.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/random.md#RandSliceFromGivenSlice)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/random.md#RandSliceFromGivenSlice)]
[[play](https://go.dev/play/p/68UikN9d6VT)] [[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/oyZbuV7bu7b)]
<h3 id="retry"> 17. Retry package is for executing a function repeatedly until it was successful or canceled by the context. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="retry"> 17. Retry package is for executing a function repeatedly until it was successful or canceled by the context. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -1575,7 +1611,12 @@ import "github.com/duke-git/lancet/v2/slice"
- **<big>Frequency</big>** : counts the frequency of each element in the slice. - **<big>Frequency</big>** : counts the frequency of each element in the slice.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Frequency)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Frequency)]
[[play](https://go.dev/play/p/CW3UVNdUZOq)] [[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/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/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. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <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. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -1666,6 +1707,12 @@ import "github.com/duke-git/lancet/v2/stream"
- **<big>ToSlice</big>** : returns the elements in the stream. - **<big>ToSlice</big>** : returns the elements in the stream.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#ToSlice)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#ToSlice)]
[[play](https://go.dev/play/p/jI6_iZZuVFE)] [[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/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/CjeoNw2eac_G)]
<h3 id="structs"> 20. Structs package provides several high level functions to manipulate struct, tag, and field. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="structs"> 20. Structs package provides several high level functions to manipulate struct, tag, and field. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -1847,6 +1894,9 @@ import "github.com/duke-git/lancet/v2/strutil"
- **<big>RegexMatchAllGroups</big>** : matches all subgroups in a string using a regular expression and returns the result. - **<big>RegexMatchAllGroups</big>** : matches all subgroups in a string using a regular expression and returns the result.
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#RegexMatchAllGroups)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#RegexMatchAllGroups)]
[[play](https://go.dev/play/p/JZiu0RXpgN-)] [[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/Ay9UIk7Rum9)]
<h3 id="system"> 22. System package contain some functions about os, runtime, shell command. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3> <h3 id="system"> 22. System package contain some functions about os, runtime, shell command. &nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
@@ -2197,6 +2247,9 @@ import "github.com/duke-git/lancet/v2/xerror"
- **<big>TryUnwrap</big>** : check if err is nil then it returns a valid value. If err is not nil, TryUnwrap panics with err. - **<big>TryUnwrap</big>** : 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)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/xerror.md#TryUnwrap)]
[[play](https://go.dev/play/p/acyZVkNZEeW)] [[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/D5Mdb0mRj0P)]
## How to Contribute ## How to Contribute
+79 -28
View File
@@ -4,7 +4,7 @@
<br/> <br/>
![Go version](https://img.shields.io/badge/go-%3E%3Dv1.18-9cf) ![Go version](https://img.shields.io/badge/go-%3E%3Dv1.18-9cf)
[![Release](https://img.shields.io/badge/release-2.3.3-green.svg)](https://github.com/duke-git/lancet/releases) [![Release](https://img.shields.io/badge/release-2.3.4-green.svg)](https://github.com/duke-git/lancet/releases)
[![GoDoc](https://godoc.org/github.com/duke-git/lancet/v2?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet/v2) [![GoDoc](https://godoc.org/github.com/duke-git/lancet/v2?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet/v2)
[![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet/v2)](https://goreportcard.com/report/github.com/duke-git/lancet/v2) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet/v2)](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
[![test](https://github.com/duke-git/lancet/actions/workflows/codecov.yml/badge.svg?branch=main&event=push)](https://github.com/duke-git/lancet/actions/workflows/codecov.yml) [![test](https://github.com/duke-git/lancet/actions/workflows/codecov.yml/badge.svg?branch=main&event=push)](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
@@ -38,7 +38,7 @@
go get github.com/duke-git/lancet/v2 //安装v2最新版本v2.x.x go get github.com/duke-git/lancet/v2 //安装v2最新版本v2.x.x
``` ```
2. <b>使用 go1.18 以下版本的用户,必须安装 v1.x.x。目前最新的 v1 版本是 v1.4.4。</b> 2. <b>使用 go1.18 以下版本的用户,必须安装 v1.x.x。目前最新的 v1 版本是 v1.4.5。</b>
```go ```go
go get github.com/duke-git/lancet// 使用go1.18以下版本, 必须安装v1.x.x版本 go get github.com/duke-git/lancet// 使用go1.18以下版本, 必须安装v1.x.x版本
@@ -321,13 +321,19 @@ import "github.com/duke-git/lancet/v2/convertor"
[[play](https://go.dev/play/p/OphmHCN_9u8)] [[play](https://go.dev/play/p/OphmHCN_9u8)]
- **<big>ToStdBase64</big>** : 将值转换为StdBase64编码的字符串。 - **<big>ToStdBase64</big>** : 将值转换为StdBase64编码的字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToStdBase64)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToStdBase64)]
[[play](https://go.dev/play/p/_fLJqJD3NMo)]
- **<big>ToUrlBase64</big>** : 将值转换为url Base64编码的字符串。 - **<big>ToUrlBase64</big>** : 将值转换为url Base64编码的字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToUrlBase64)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToUrlBase64)]
[[play](https://go.dev/play/p/C_d0GlvEeUR)]
- **<big>ToRawStdBase64</big>** : 将值转换为RawStdBase64编码的字符串。 - **<big>ToRawStdBase64</big>** : 将值转换为RawStdBase64编码的字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawStdBase64)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawStdBase64)]
[[play](https://go.dev/play/p/wSAr3sfkDcv)]
- **<big>ToRawUrlBase64</big>** : 将值转换为RawUrlBase64编码的字符串。 - **<big>ToRawUrlBase64</big>** : 将值转换为RawUrlBase64编码的字符串。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawUrlBase64)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawUrlBase64)]
[[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/X3itkCxwB_x)]
<h3 id="cryptor"> 6. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="cryptor"> 6. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -464,10 +470,10 @@ import "github.com/duke-git/lancet/v2/cryptor"
[[play](https://go.dev/play/p/zutRHrDqs0X)] [[play](https://go.dev/play/p/zutRHrDqs0X)]
- **<big>RsaEncrypt</big>** : 用公钥文件 ras 加密数据。 - **<big>RsaEncrypt</big>** : 用公钥文件 ras 加密数据。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaEncrypt)] [[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 解密数据。 - **<big>RsaDecrypt</big>** : 用私钥文件 rsa 解密数据。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaDecrypt)] [[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。 - **<big>GenerateRsaKeyPair</big>** : 创建rsa公钥私钥和key。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#GenerateRsaKeyPair)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#GenerateRsaKeyPair)]
[[play](https://go.dev/play/p/sSVmkfENKMz)] [[play](https://go.dev/play/p/sSVmkfENKMz)]
@@ -477,7 +483,12 @@ import "github.com/duke-git/lancet/v2/cryptor"
- **<big>RsaDecryptOAEP</big>** : rsa OAEP解密。 - **<big>RsaDecryptOAEP</big>** : rsa OAEP解密。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaDecryptOAEP)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/cryptor.md#RsaDecryptOAEP)]
[[play](https://go.dev/play/p/sSVmkfENKMz)] [[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/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/qhsbf8BJ6Mf)]
<h3 id="datetime"> 7. datetime日期时间处理包,格式化日期,比较日期。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="datetime"> 7. datetime日期时间处理包,格式化日期,比较日期。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -622,6 +633,15 @@ import "github.com/duke-git/lancet/v2/datetime"
- **<big>GenerateDatetimesBetween</big>** : 生成从start到end的所有日期时间的字符串列表。 - **<big>GenerateDatetimesBetween</big>** : 生成从start到end的所有日期时间的字符串列表。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#GenerateDatetimesBetween)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#GenerateDatetimesBetween)]
[[play](https://go.dev/play/p/6kHBpAxD9ZC)] [[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/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/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/rbW51cDtM_2)]
<h3 id="datastructure"> 8. datastructure 包含一些普通的数据结构实现。例如:list, linklist, stack, queue, set, tree, graph。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="datastructure"> 8. datastructure 包含一些普通的数据结构实现。例如:list, linklist, stack, queue, set, tree, graph。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -754,7 +774,9 @@ import "github.com/duke-git/lancet/v2/fileutil"
- **<big>ParallelChunkRead</big>** : 并行读取文件并将每个块的行发送到指定通道。 - **<big>ParallelChunkRead</big>** : 并行读取文件并将每个块的行发送到指定通道。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ParallelChunkRead)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ParallelChunkRead)]
[[play](https://go.dev/play/p/teMXnCsdSEw)] [[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/iLRrDBhE38E)]
<h3 id="formatter"> 10. formatter 格式化器包含一些数据格式化处理方法。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="formatter"> 10. formatter 格式化器包含一些数据格式化处理方法。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -1121,7 +1143,18 @@ import "github.com/duke-git/lancet/v2/mathutil"
- **<big>Div</big>** : 除法运算。 - **<big>Div</big>** : 除法运算。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Div)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Div)]
[[play](https://go.dev/play/p/WLxDdGXXYat)] [[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/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/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/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/ENFQRDQUFi9)]
<h3 id="netutil"> 14. netutil 网络包支持获取 ip 地址,发送 http 请求。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="netutil"> 14. netutil 网络包支持获取 ip 地址,发送 http 请求。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -1282,7 +1315,9 @@ import "github.com/duke-git/lancet/v2/random"
- **<big>RandSliceFromGivenSlice</big>** : 从给定切片中生成长度为 num 的随机切片。 - **<big>RandSliceFromGivenSlice</big>** : 从给定切片中生成长度为 num 的随机切片。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandSliceFromGivenSlice)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/random.md#RandSliceFromGivenSlice)]
[[play](https://go.dev/play/p/68UikN9d6VT)] [[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/oyZbuV7bu7b)]
<h3 id="retry"> 17. retry 重试执行函数直到函数运行成功或被 context cancel。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="retry"> 17. retry 重试执行函数直到函数运行成功或被 context cancel。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -1301,7 +1336,7 @@ import "github.com/duke-git/lancet/v2/retry"
- **<big>RetryFunc</big>** : 重试执行的函数。 - **<big>RetryFunc</big>** : 重试执行的函数。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryFunc)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryFunc)]
[[play](https://go.dev/play/p/nk2XRmagfVF)] [[play](https://go.dev/play/p/nk2XRmagfVF)]
- **<big>RetryTimes</big>** : 设置重试次数,默认 5。 - **<big>RetryTimes</big>** : 设置重试次数,默认5。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryTimes)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/retry.md#RetryTimes)]
[[play](https://go.dev/play/p/ssfVeU2SwLO)] [[play](https://go.dev/play/p/ssfVeU2SwLO)]
- **<big>BackoffStrategy</big>** : 定义计算退避间隔的方法的接口。 - **<big>BackoffStrategy</big>** : 定义计算退避间隔的方法的接口。
@@ -1573,7 +1608,12 @@ import "github.com/duke-git/lancet/v2/slice"
- **<big>Frequency</big>** : 计算切片中每个元素出现的频率。 - **<big>Frequency</big>** : 计算切片中每个元素出现的频率。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Frequency)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Frequency)]
[[play](https://go.dev/play/p/CW3UVNdUZOq)] [[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/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/6QcUpcY4UMW)]
<h3 id="stream"> 19. stream 流,该包仅验证简单的 stream 实现,功能有限。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="stream"> 19. stream 流,该包仅验证简单的 stream 实现,功能有限。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -1664,7 +1704,12 @@ import "github.com/duke-git/lancet/v2/stream"
- **<big>ToSlice</big>** : 返回 stream 中的元素切片。 - **<big>ToSlice</big>** : 返回 stream 中的元素切片。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#ToSlice)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#ToSlice)]
[[play](https://go.dev/play/p/jI6_iZZuVFE)] [[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/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/CjeoNw2eac_G)]
<h3 id="structs"> 20. structs 提供操作 struct, tag, field 的相关函数。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="structs"> 20. structs 提供操作 struct, tag, field 的相关函数。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -1849,6 +1894,9 @@ import "github.com/duke-git/lancet/v2/strutil"
- **<big>RegexMatchAllGroups</big>** : 使用正则表达式匹配字符串中的所有子组并返回结果。 - **<big>RegexMatchAllGroups</big>** : 使用正则表达式匹配字符串中的所有子组并返回结果。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#RegexMatchAllGroups)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#RegexMatchAllGroups)]
[[play](https://go.dev/play/p/JZiu0RXpgN-)] [[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/Ay9UIk7Rum9)]
<h3 id="system"> 22. system 包含 os, runtime, shell command 的相关函数。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3> <h3 id="system"> 22. system 包含 os, runtime, shell command 的相关函数。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
@@ -2061,7 +2109,7 @@ import "github.com/duke-git/lancet/v2/validator"
- **<big>IsCreditCard</big>** : 验证字符串是否是信用卡号码。 - **<big>IsCreditCard</big>** : 验证字符串是否是信用卡号码。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsCreditCard)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsCreditCard)]
[[play](https://go.dev/play/p/sNwwL6B0-v4)] [[play](https://go.dev/play/p/sNwwL6B0-v4)]
- **<big>IsDns</big>** : 验证字符串是否是有效 dns。 - **<big>IsDns</big>** : 验证字符串是否是有效dns。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsDns)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsDns)]
[[play](https://go.dev/play/p/jlYApVLLGTZ)] [[play](https://go.dev/play/p/jlYApVLLGTZ)]
- **<big>IsEmail</big>** : 验证字符串是否是有效电子邮件地址。 - **<big>IsEmail</big>** : 验证字符串是否是有效电子邮件地址。
@@ -2097,10 +2145,10 @@ import "github.com/duke-git/lancet/v2/validator"
- **<big>IsIp</big>** : 验证字符串是否是 ip 地址。 - **<big>IsIp</big>** : 验证字符串是否是 ip 地址。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIp)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIp)]
[[play](https://go.dev/play/p/FgcplDvmxoD)] [[play](https://go.dev/play/p/FgcplDvmxoD)]
- **<big>IsIpV4</big>** : 验证字符串是否是 ipv4 地址。 - **<big>IsIpV4</big>** : 验证字符串是否是ipv4地址。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpV4)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpV4)]
[[play](https://go.dev/play/p/zBGT99EjaIu)] [[play](https://go.dev/play/p/zBGT99EjaIu)]
- **<big>IsIpV6</big>** : 验证字符串是否是 ipv6 地址。 - **<big>IsIpV6</big>** : 验证字符串是否是ipv6地址。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpV6)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpV6)]
[[play](https://go.dev/play/p/AHA0r0AzIdC)] [[play](https://go.dev/play/p/AHA0r0AzIdC)]
- **<big>IsStrongPassword</big>** : 验证字符串是否是强密码:(字母+数字+特殊字符)。 - **<big>IsStrongPassword</big>** : 验证字符串是否是强密码:(字母+数字+特殊字符)。
@@ -2115,10 +2163,10 @@ import "github.com/duke-git/lancet/v2/validator"
- **<big>IsZeroValue</big>** : 判断传入的参数值是否为零值。 - **<big>IsZeroValue</big>** : 判断传入的参数值是否为零值。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsZeroValue)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsZeroValue)]
[[play](https://go.dev/play/p/UMrwaDCi_t4)] [[play](https://go.dev/play/p/UMrwaDCi_t4)]
- **<big>IsGBK</big>** : 检查数据编码是否为 gbk(汉字内部代码扩展规范)。 - **<big>IsGBK</big>** : 检查数据编码是否为gbk(汉字内部代码扩展规范)。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsGBK)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsGBK)]
[[play](https://go.dev/play/p/E2nt3unlmzP)] [[play](https://go.dev/play/p/E2nt3unlmzP)]
- **<big>IsASCII</big>** : 验证字符串全部为 ASCII 字符。 - **<big>IsASCII</big>** : 验证字符串全部为ASCII字符。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsASCII)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsASCII)]
[[play](https://go.dev/play/p/hfQNPLX0jNa)] [[play](https://go.dev/play/p/hfQNPLX0jNa)]
- **<big>IsPrintable</big>** : 检查字符串是否全部为可打印字符。 - **<big>IsPrintable</big>** : 检查字符串是否全部为可打印字符。
@@ -2133,13 +2181,13 @@ import "github.com/duke-git/lancet/v2/validator"
- **<big>IsBase64URL</big>** : 检查字符串是否是有效的 base64 url。 - **<big>IsBase64URL</big>** : 检查字符串是否是有效的 base64 url。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsBase64URL)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsBase64URL)]
[[play](https://go.dev/play/p/vhl4mr8GZ6S)] [[play](https://go.dev/play/p/vhl4mr8GZ6S)]
- **<big>IsJWT</big>** : 检查字符串是否是有效的 JSON Web Token (JWT)。 - **<big>IsJWT</big>** : 检查字符串是否是有效的JSON Web Token (JWT)。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsJWT)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsJWT)]
[[play](https://go.dev/play/p/R6Op7heJbKI)] [[play](https://go.dev/play/p/R6Op7heJbKI)]
- **<big>IsVisa</big>** : 检查字符串是否是有效的 visa 卡号。 - **<big>IsVisa</big>** : 检查字符串是否是有效的visa卡号。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsVisa)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsVisa)]
[[play](https://go.dev/play/p/SdS2keOyJsl)] [[play](https://go.dev/play/p/SdS2keOyJsl)]
- **<big>IsMasterCard</big>** : 检查字符串是否是有效的 MasterCard 卡号。 - **<big>IsMasterCard</big>** : 检查字符串是否是有效的MasterCard卡号。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsMasterCard)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsMasterCard)]
[[play](https://go.dev/play/p/CwWBFRrG27b)] [[play](https://go.dev/play/p/CwWBFRrG27b)]
- **<big>IsAmericanExpress</big>** : 检查字符串是否是有效的 American Express 卡号。 - **<big>IsAmericanExpress</big>** : 检查字符串是否是有效的 American Express 卡号。
@@ -2175,30 +2223,33 @@ import "github.com/duke-git/lancet/v2/xerror"
- **<big>XError_Unwrap</big>** : 解构 XEerror 为 error 对象。适配 github.com/pkg/errors。 - **<big>XError_Unwrap</big>** : 解构 XEerror 为 error 对象。适配 github.com/pkg/errors。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Unwrap) [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Unwrap)
[[play](https://go.dev/play/p/VUXJ8BST4c6)] [[play](https://go.dev/play/p/VUXJ8BST4c6)]
- **<big>XError_With</big>** : 添加与 XError 对象的键和值。 - **<big>XError_With</big>** : 添加与XError对象的键和值。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_With)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_With)]
[[play](https://go.dev/play/p/ow8UISXX_Dp)] [[play](https://go.dev/play/p/ow8UISXX_Dp)]
- **<big>XError_Id</big>** : 设置 XError 对象的 id。 - **<big>XError_Id</big>** : 设置XError对象的id。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#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)] [[play](https://go.dev/play/p/X6HBlsy58U9)]
- **<big>XError_Is</big>** : 检查目标 error 是否为 XError,两个错误中的 error.id 是否匹配。 - **<big>XError_Is</big>** : 检查目标error是否为XError,两个错误中的error.id是否匹配。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Is)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Is)]
[[play](https://go.dev/play/p/X6HBlsy58U9)] [[play](https://go.dev/play/p/X6HBlsy58U9)]
- **<big>XError_Values</big>** : 返回由 With 设置的键和值的映射。将合并所有 XError 键和值。 - **<big>XError_Values</big>** : 返回由With设置的键和值的映射。将合并所有XError键和值。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Values)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Values)]
[[play](https://go.dev/play/p/ow8UISXX_Dp)] [[play](https://go.dev/play/p/ow8UISXX_Dp)]
- **<big>XError_StackTrace</big>** : 返回与 pkg/error 兼容的堆栈信息。 - **<big>XError_StackTrace</big>** : 返回与pkg/error兼容的堆栈信息。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_StackTrace)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_StackTrace)]
[[play](https://go.dev/play/p/6FAvSQpa7pc)] [[play](https://go.dev/play/p/6FAvSQpa7pc)]
- **<big>XError_Info</big>** : 返回可打印的 XError 对象信息。 - **<big>XError_Info</big>** : 返回可打印的XError对象信息。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Info)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Info)]
[[play](https://go.dev/play/p/1ZX0ME1F-Jb)] [[play](https://go.dev/play/p/1ZX0ME1F-Jb)]
- **<big>XError_Error</big>** : 实现标准库的 error 接口。 - **<big>XError_Error</big>** : 实现标准库的error接口。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Error)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Error)]
[[play](https://go.dev/play/p/w4oWZts7q7f)] [[play](https://go.dev/play/p/w4oWZts7q7f)]
- **<big>TryUnwrap</big>** : 检查 error, 如果 errnil 则展开,则它返回一个有效值,如果 err 不是 nilUnwrap 使用 err 发生 panic。 - **<big>TryUnwrap</big>** : 检查error, 如果errnil则展开,则它返回一个有效值,如果err不是nilUnwrap使用err发生panic。
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#TryUnwrap)] [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#TryUnwrap)]
[[play](https://go.dev/play/p/acyZVkNZEeW)] [[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/D5Mdb0mRj0P)]
## 如何贡献代码 ## 如何贡献代码
+2 -6
View File
@@ -143,12 +143,8 @@ func ToString(value any) string {
if err != nil { if err != nil {
return "" return ""
} }
return string(b)
// todo: maybe we should't supprt other type conversion return string(b)
// v := reflect.ValueOf(value)
// log.Panicf("Unsupported data type: %s ", v.String())
// return ""
} }
} }
@@ -486,7 +482,7 @@ func ToRawUrlBase64(value any) string {
} }
// 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
// Play: todo // Play: https://go.dev/play/p/X3itkCxwB_x
func ToBigInt[T any](v T) (*big.Int, error) { func ToBigInt[T any](v T) (*big.Int, error) {
result := new(big.Int) result := new(big.Int)
+4 -5
View File
@@ -565,7 +565,7 @@ func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error {
} }
// RsaEncrypt encrypt data with ras algorithm. // 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 { func RsaEncrypt(data []byte, pubKeyFileName string) []byte {
file, err := os.Open(pubKeyFileName) file, err := os.Open(pubKeyFileName)
if err != nil { if err != nil {
@@ -600,7 +600,7 @@ func RsaEncrypt(data []byte, pubKeyFileName string) []byte {
} }
// RsaDecrypt decrypt data with ras algorithm. // 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 { func RsaDecrypt(data []byte, privateKeyFileName string) []byte {
file, err := os.Open(privateKeyFileName) file, err := os.Open(privateKeyFileName)
if err != nil { if err != nil {
@@ -663,7 +663,7 @@ func RsaDecryptOAEP(ciphertext []byte, label []byte, key rsa.PrivateKey) ([]byte
} }
// RsaSign signs the data with RSA. // 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) { func RsaSign(hash crypto.Hash, data []byte, privateKeyFileName string) ([]byte, error) {
privateKey, err := loadRasPrivateKey(privateKeyFileName) privateKey, err := loadRasPrivateKey(privateKeyFileName)
if err != nil { 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. // 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 { func RsaVerifySign(hash crypto.Hash, data, signature []byte, pubKeyFileName string) error {
publicKey, err := loadRsaPublicKey(pubKeyFileName) publicKey, err := loadRsaPublicKey(pubKeyFileName)
if err != nil { if err != nil {
@@ -712,7 +712,6 @@ func loadRsaPublicKey(filename string) (*rsa.PublicKey, error) {
if blockType == "RSA PUBLIC KEY" { if blockType == "RSA PUBLIC KEY" {
pubKey, err = x509.ParsePKCS1PublicKey(block.Bytes) pubKey, err = x509.ParsePKCS1PublicKey(block.Bytes)
if err != nil { if err != nil {
// todo: here should be a bug, should return nil, err
key, err := x509.ParsePKIXPublicKey(block.Bytes) key, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil { if err != nil {
return nil, err return nil, err
+51
View File
@@ -0,0 +1,51 @@
-----BEGIN rsa private key-----
MIIJKAIBAAKCAgEA5IqWfYbW1NlTDWE2plFWqD6CTquA0Ar/1E66lY8OMtrdpxTm
chirmoISWN0BD7r2tV9T/kHs44Sy3raAfkR5ixYF5FRkb63FdIAtoynsxS6MEE26
fgWuDAa1xwNt+t/uivnpfJk25htpBNkKGT8ii0TPPLn1N15hMHenT6PzW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kIcT6HDSasFD1RDWzQhJZ6vVEpe5rRHUL3OfYlS
/M1TytqKLl09SFUIvCPFy3d5/4XljRsfQeJq8/hQdW8HdOCcgTjEttSyqr+hSWvH
xh192wKCAQB0uSY3u2XTCH9zrTMJ/HErn+7gd76REsW4JmvDjEEOHHawkJnH8SlP
KCKqcMTPWZWvEUcM0njytolPVw6ap0OPQD9reHP1lt64iwK7mB/R3gy/yztSi6kH
VvCBoqLKlfwvnUUvrNBAEsER/rxc/FXqw+tlKMbnE7RUYXeml28rQzLcsfEws7PC
Adi717QeATQWstYnObL2pHjTHSOA+ee0Hx3qoNith3M8DuQlfkH1QiNFPLDpnXhv
N5IpU3fbrNihsm/InvFon3rCONkoKAQUt6LvyOqWusSiB5Im+9g06rhinXwvJ0Ge
eMMW65nVU/FelwUWWeo3f08LlHE6tLL3AoIBABcc549sTCMhBmQS9prESurzhPVk
HCFYlR/GdlfNmRtTYssk25xaG+tiaEzXi7DXBq20TGNOATgoX7l9EWIRXkDuR6hS
aRXyn+CVU3y2dhpGZBf+EUWP0u9TNSJ/RFO0ViAriL5J9kjF9hFvG36B9kRSiMrn
mCp9NCdtRYOHjzkvbY5uRMqP8H4/nAXNMA+odPnOPDUOIcH2ztaFOtQgZxa9x/eS
eGmnJ/V/rLvS04uVw5d7juJstEspnM4MxPHSFEDN7NG13bN+c1jTY1/85icIeRBi
nP47M2kDQ6RrEdgYfPbdlx1wGdTUIeAm3duptTiwpwa5Q2Js22TMJYRTnbM=
-----END rsa private key-----
+49 -49
View File
@@ -1,51 +1,51 @@
-----BEGIN rsa private key----- -----BEGIN rsa private key-----
MIIJKQIBAAKCAgEA66tu9qYNO0QeeeMaEJohWeBS7KdPQwVFt+5+kRhPST+xI6A8 MIIJJwIBAAKCAgEA00EXXa5qy/g4DLIedOhboYGZoS/S9B7qy5nHbxum6bt0Y+U5
TtfccOtZM4Zc7BnSfTTQvcvF6HhOOn+PDYoiVr/2dK4yZHm7wH35riqtvv0TYVNT DheGNielHwDz3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I0v3pQ8Hk2pe5AoIBAQDKVG3BQi3gbNIOT3wWGyMgaADT nNJ6sIhn1Zhr6nMc9VUNmfAZ/tugbPECggEAC0F2v/i+qoNbKzvjgzPdBTIFkeRw
5f97nmq/8a/BvylEYL17dUqS4sB+ARGbKehXr+WknBtNUKdvfnufN7jwNfb1TfDm wvrAeZlWvGJySd9CG7kjMkrHyr5RIfuns5tmhWsmPeMY0zssmW4Yin0uO5cVmoTt
aVue2PF/Twicd81CKxAZkwlvYBUMoSNj+djVQuN5KMk8+0N0zedEiG0jxwhu61sN SzmJznty0Tfi2h0gbhbDu0s/lHv7qk8piN+6ITREcmJm6HZxXPWRsgs1YUuxed2L
dLJg68c46MdxWcFtM2OJeNLDtM07eF7LcJ9yagdgDV1sROLsIf0NY08PDwMEt/1E aFFcXT403kxYIIyngCPWbeZHNrqD23I6KBfJi+/mBVl+/win8O5wmWmX5UDQLohE
eV34Z7faYoO7tYOT4so45ldfLDENoyp7mnOyKYGEx8L0lxfwLIqltF959RS0K+dV Y2bp8nmOqIk3yD+BeCIMQOsCqoWq+Nl0PtEueRhdF4qmvl65KPGPg5d5OzzZHRcG
0g9MJCZimpjLiBGwSz4ZxTFGC8wmsX0upA/K8W7LUxYV6mmbCenvikJPBRQn rHov/p7TM7bCKTGRDqjlYrUgeUDFD7h0wMgBYSvFE2uk7GMo0/aJwc9wPg==
-----END rsa private key----- -----END rsa private key-----
+14
View File
@@ -0,0 +1,14 @@
-----BEGIN rsa public key-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA5IqWfYbW1NlTDWE2plFW
qD6CTquA0Ar/1E66lY8OMtrdpxTmchirmoISWN0BD7r2tV9T/kHs44Sy3raAfkR5
ixYF5FRkb63FdIAtoynsxS6MEE26fgWuDAa1xwNt+t/uivnpfJk25htpBNkKGT8i
i0TPPLn1N15hMHenT6PzWVjGjQxWcp4dUA4gXTDuqaeu7Oy7Ku2yP90/ra+cjTV8
DnBJ9enQhAfu1LivJO3FgmXeuC3uqhhM3t9ZbNy7tvJI5PXDCaS8iesBvCp5carT
SXWLpFEgvIhXQIsXtxezKAP3gRd8r5JPQI9FZlxyUcyf+Htkn2A4qyKhFElnP1z9
j0YLFhL/gQMdtNIY7yhSb29PyuCG7noz25swrfxbA7ZVppM0J19JNhlpqmusBKLB
NqN+KMD8EDli7NLX17S9Dj2pQF9I8fVXPEhkdTb67rr7y3OUANKjh0Opnt3JLoj9
u1X7BfCeUSR/qq3E8RFPeyxvP1tc5QVqKBG6UPBo8nLQqdzJhUd8a1YEfXIUbdHL
s2q5WVFu2MDavIp634+fzfcIFRoBtdxf5aCdxLaLocsA/aLLyL1pK6K0rpdrSUtc
EBMST26qIlU0Ht+SQtaMdE2gyjkMM5RpLh1q/gpow+0j3zu6f5tDsu3qwgjLIx78
YCTGUuCpsVMzFK4tahYSPNkCAwEAAQ==
-----END rsa public key-----
+12 -12
View File
@@ -1,14 +1,14 @@
-----BEGIN rsa public key----- -----BEGIN rsa public key-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA66tu9qYNO0QeeeMaEJoh MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA00EXXa5qy/g4DLIedOhb
WeBS7KdPQwVFt+5+kRhPST+xI6A8TtfccOtZM4Zc7BnSfTTQvcvF6HhOOn+PDYoi oYGZoS/S9B7qy5nHbxum6bt0Y+U5DheGNielHwDz3k2WJYk75KZI9eoDdC4d8C9d
Vr/2dK4yZHm7wH35riqtvv0TYVNTdeKDmW3vZy8SR7Cpedl5a+BEc7D1PBqHMwFn gWuf1FQmIFu9OtjGiPt+WdYpKJUD1OXNiipx44xDsGYc4daBfLlNujhYQjWVfh7q
f/aJLY3AWp8VbHf0g1HcIL1xTXsFXFn283zUEHrg1XNmJlT0nLuKaBjIqGBqWZWI y62jXbPfJJYC9VFNkg9T36ejzjpFiXSM678rdRq9lIcisY75ez1z6ksdnv8GetNJ
fCyOK5ZhhKP9vhRhY+u+/HQ1+CLw66qzAN6ZngR6Ra6B0bvx0D38Hy/FxLonDaut pC7W/4Ij0vNndi9R2hlclV5+IxGu7nB5us13IwJSTnyKokS6Mjh/sLiHvF+7OUWR
ozd17C+zwQ6V5/PHLDRAqcZRvJUJ3E163gGEjBOTLU5T4FGxOaSBO4Dpw6J+wJRF WlTs2qvBuTTk3F7zrzOHvBs+6b/nUBqMBKqhzTcjK2njg9DuQj3IhmyHgcYKWwC2
uOyq3fB6M62R5x66U53p3GlWpNWsYkN3mk3JfI0+xsbi/Ry5jhdXOHANrks7eoo8 KucsuUW/xbFQCceemHGzZ2kceDHYUNUg4UncWXKF466uS93y4fdUeFTe9ojyearY
SoAOEWidMZGRYpkiTkFgMHmjsrM5sUmsEpM+B93Kouij3CH3p9KAzfAz/I573pBz w9Ip/9CA9ERq04h44KJA3HGVpCPxrk3pqM3gfzAR7T7gzZQjotPwuGrGT84jcOvc
3xuXDsbhlQIncRLOIFXP/VxU/IUsf81blhsWZ8ZQg1HyB7vWDyAR0BFuIKWDMlzn CYRcJnIm/5xQaIT9N1iEkyDZaH0rXiFttn2zsNOTYuASj5Z+Y4AfH3+dBc1ebWjZ
M85kMoPpCpI1UUfOw1hLQwHRBuVIU8v+lgJhimHZtrDPEvOmXLTGBJLUePFEMI7l UIurgq3JJUmplArD6k99Y3qH9nHArrRMRC7iyEsVwOWYMcadkF6l+pVYAXnxy6nA
bL9XQTkMBXRgJ7hjxfYutUv6WpoyYP/vfUq7GN6X4JQzgCd1timJc/ljqTDbzT5N NMpwM5DOiKY4jhZ5QMyp1E4oQtGNlrV/mqdOHXM3Gb5Vclw0JiQ1LMOihoURliuh
Gxk8mhjoAhZFpRciSyt5+6MCAwEAAQ== wxj4u6AJMnILHBGQQ5P3NQsCAwEAAQ==
-----END rsa public key----- -----END rsa public key-----
-6
View File
@@ -100,12 +100,6 @@ func TestBSTree_Delete(t *testing.T) {
acturl1 := bstree.InOrderTraverse() acturl1 := bstree.InOrderTraverse()
assert.Equal([]int{2, 5, 6, 7}, acturl1) assert.Equal([]int{2, 5, 6, 7}, acturl1)
//todo
// bstree.DeletetNode(6, comparator)
// bstree.Print()
// acturl2 := bstree.InOrderTraverse()
// assert.Equal([]int{2, 5, 7}, acturl2)
} }
func TestBSTree_Depth(t *testing.T) { func TestBSTree_Depth(t *testing.T) {
+3 -3
View File
@@ -445,7 +445,7 @@ func GenerateDatetimesBetween(start, end time.Time, layout string, interval stri
} }
// Min returns the earliest time among the given times. // 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 { func Min(t1 time.Time, times ...time.Time) time.Time {
minTime := t1 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. // 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 { func Max(t1 time.Time, times ...time.Time) time.Time {
maxTime := t1 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. // 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) { func MaxMin(t1 time.Time, times ...time.Time) (maxTime time.Time, minTime time.Time) {
maxTime = t1 maxTime = t1
minTime = t1 minTime = t1
+1 -1
View File
@@ -1155,7 +1155,7 @@ func main() {
<p>将整数值转换为bigInt。</p> <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 ```go
func ToBigInt[T any](v T) (*big.Int, error) func ToBigInt[T any](v T) (*big.Int, error)
+8 -8
View File
@@ -1436,7 +1436,7 @@ func main() {
func RsaEncrypt(data []byte, pubKeyFileName string) []byte 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 ```go
package main package main
@@ -1473,7 +1473,7 @@ func main() {
func RsaDecrypt(data []byte, privateKeyFileName string) []byte 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 ```go
package main package main
@@ -1621,7 +1621,7 @@ func main() {
func RsaSign(hash crypto.Hash, data []byte, privateKeyFileName string) ([]byte, error) 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 ```go
package main package main
@@ -1638,12 +1638,12 @@ func main() {
privateKey := "./rsa_private.pem" privateKey := "./rsa_private.pem"
publicKey := "./rsa_public.pem" publicKey := "./rsa_public.pem"
signature, err := RsaSign(hash, data, privateKey) signature, err := cryptor.RsaSign(hash, data, privateKey)
if err != nil { if err != nil {
return return
} }
err = RsaVerifySign(hash, data, signature, publicKey) err = cryptor.RsaVerifySign(hash, data, signature, publicKey)
if err != nil { if err != nil {
return return
} }
@@ -1660,7 +1660,7 @@ func main() {
func RsaVerifySign(hash crypto.Hash, data, signature []byte, pubKeyFileName string) error 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 ```go
package main package main
@@ -1677,12 +1677,12 @@ func main() {
privateKey := "./rsa_private.pem" privateKey := "./rsa_private.pem"
publicKey := "./rsa_public.pem" publicKey := "./rsa_public.pem"
signature, err := RsaSign(hash, data, privateKey) signature, err := cryptor.RsaSign(hash, data, privateKey)
if err != nil { if err != nil {
return return
} }
err = RsaVerifySign(hash, data, signature, publicKey) err = cryptor.RsaVerifySign(hash, data, signature, publicKey)
if err != nil { if err != nil {
return return
} }
+3 -3
View File
@@ -1585,7 +1585,7 @@ func main() {
func Min(t1 time.Time, times ...time.Time) time.Time 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 ```go
package main package main
@@ -1615,7 +1615,7 @@ func main() {
func Max(t1 time.Time, times ...time.Time) time.Time 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 ```go
package main package main
@@ -1645,7 +1645,7 @@ func main() {
func MaxMin(t1 time.Time, times ...time.Time) (maxTime time.Time, minTime time.Time) 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 ```go
package main package main
+1 -1
View File
@@ -1088,7 +1088,7 @@ func main() {
func GetExeOrDllVersion(filePath string) (string, error) 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 ```go
package main package main
+8 -8
View File
@@ -1178,7 +1178,7 @@ func main() {
func Variance[T constraints.Float | constraints.Integer](numbers []T) float64 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 ```go
package main package main
@@ -1211,7 +1211,7 @@ func main() {
func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64 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 ```go
package main package main
@@ -1222,8 +1222,8 @@ import (
) )
func main() { func main() {
result1 := mathutil.T运行cRound(mathutil.StdDev([]int{1, 2, 3, 4, 5}), 2) result1 := mathutil.TruncRound(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) result2 := mathutil.TruncRound(mathutil.StdDev([]float64{1.1, 2.2, 3.3, 4.4, 5.5}), 2)
fmt.Println(result1) fmt.Println(result1)
fmt.Println(result2) fmt.Println(result2)
@@ -1236,7 +1236,7 @@ func main() {
### <span id="Permutation">Permutation</span> ### <span id="Permutation">Permutation</span>
<p>计算排列数P(n, k)。</p> <p>计算排列数P(n, k)。</p>
<b>函数签名:</b> <b>函数签名:</b>
@@ -1244,7 +1244,7 @@ func main() {
func Permutation(n, k uint) uint 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 ```go
package main package main
@@ -1269,7 +1269,7 @@ func main() {
### <span id="Combination">Combination</span> ### <span id="Combination">Combination</span>
<p>计算组合数C(n, k)。</p> <p>计算组合数C(n, k)。</p>
<b>函数签名:</b> <b>函数签名:</b>
@@ -1277,7 +1277,7 @@ func main() {
func Combination(n, k uint) uint 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 ```go
package main package main
+2 -2
View File
@@ -526,7 +526,7 @@ func main() {
``` ```
### <span id="RandNumberOfLength">RandNumberOfLength</span> ### <span id="RandNumberOfLength">RandNumberOfLength</span>
<p>生成指定长度的随机数</p> <p>生成指定长度的随机数</p>
<b>函数签名:</b> <b>函数签名:</b>
@@ -534,7 +534,7 @@ func main() {
func RandNumberOfLength(len int) int 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 ```go
package main package main
+2 -2
View File
@@ -2999,7 +2999,7 @@ func main() {
func JoinFunc[T any](slice []T, sep string, transform func(T) T) string 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 ```go
import ( import (
@@ -3029,7 +3029,7 @@ func main() {
func ConcatBy[T any](slice []T, sep T, connector func(T, T) T) T 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 ```go
import ( import (
+2 -2
View File
@@ -951,7 +951,7 @@ func main() {
func (s Stream[T]) IndexOf(target T, equal func(a, b T) bool) int 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 ```go
import ( import (
@@ -984,7 +984,7 @@ func main() {
func (s Stream[T]) LastIndexOf(target T, equal func(a, b T) bool) int 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 ```go
import ( import (
+1 -1
View File
@@ -1741,7 +1741,7 @@ func main() {
func ExtractContent(s, start, end string) []string 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 ```go
import ( import (
+1 -3
View File
@@ -509,7 +509,7 @@ func (tc *TryCatch) Finally(finallyFunc func(ctx context.Context)) *TryCatch
func (tc *TryCatch) Do() 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 ```go
package main package main
@@ -529,8 +529,6 @@ func main() {
return errors.New("error in try block") return errors.New("error in try block")
}).Catch(func(ctx context.Context, err error) { }).Catch(func(ctx context.Context, err error) {
calledCatch = true calledCatch = true
// Error in try block at /path/xxx.go:{line_number} - Cause: error message
// fmt.Println(err.Error())
}).Finally(func(ctx context.Context) { }).Finally(func(ctx context.Context) {
calledFinally = true calledFinally = true
}).Do() }).Do()
+1 -1
View File
@@ -1123,7 +1123,7 @@ func main() {
<p>Converts an integer of any supported type (int, int64, uint64, etc.) to *big.Int</p> <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 ```go
func ToBigInt[T any](v T) (*big.Int, error) func ToBigInt[T any](v T) (*big.Int, error)
+4 -4
View File
@@ -1435,7 +1435,7 @@ func main() {
func RsaEncrypt(data []byte, pubKeyFileName string) []byte 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 ```go
package main package main
@@ -1472,7 +1472,7 @@ func main() {
func RsaDecrypt(data []byte, privateKeyFileName string) []byte 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 ```go
package main package main
@@ -1620,7 +1620,7 @@ func main() {
func RsaSign(hash crypto.Hash, data []byte, privateKeyFileName string) ([]byte, error) 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 ```go
package main package main
@@ -1659,7 +1659,7 @@ func main() {
func RsaVerifySign(hash crypto.Hash, data, signature []byte, pubKeyFileName string) error 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 ```go
package main package main
+3 -3
View File
@@ -1586,7 +1586,7 @@ func main() {
func Min(t1 time.Time, times ...time.Time) time.Time 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 ```go
package main package main
@@ -1616,7 +1616,7 @@ func main() {
func Max(t1 time.Time, times ...time.Time) time.Time 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 ```go
package main package main
@@ -1646,7 +1646,7 @@ func main() {
func MaxMin(t1 time.Time, times ...time.Time) (maxTime time.Time, minTime time.Time) 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 ```go
package main package main
+1 -1
View File
@@ -1087,7 +1087,7 @@ func main() {
func GetExeOrDllVersion(filePath string) (string, error) 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 ```go
package main package main
+4 -4
View File
@@ -1177,7 +1177,7 @@ func main() {
func Variance[T constraints.Float | constraints.Integer](numbers []T) float64 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 ```go
package main package main
@@ -1210,7 +1210,7 @@ func main() {
func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64 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 ```go
package main package main
@@ -1243,7 +1243,7 @@ func main() {
func Permutation(n, k uint) uint 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 ```go
package main package main
@@ -1276,7 +1276,7 @@ func main() {
func Combination(n, k uint) uint 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 ```go
package main package main
+1 -1
View File
@@ -536,7 +536,7 @@ func main() {
func RandNumberOfLength(len int) int 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 ```go
package main package main
+2 -2
View File
@@ -2995,7 +2995,7 @@ func main() {
func JoinFunc[T any](slice []T, sep string, transform func(T) T) string 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 ```go
import ( import (
@@ -3025,7 +3025,7 @@ func main() {
func ConcatBy[T any](slice []T, sep T, connector func(T, T) T) T 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 ```go
import ( import (
+2 -2
View File
@@ -950,7 +950,7 @@ func main() {
func (s Stream[T]) IndexOf(target T, equal func(a, b T) bool) int 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 ```go
import ( import (
@@ -983,7 +983,7 @@ func main() {
func (s Stream[T]) LastIndexOf(target T, equal func(a, b T) bool) int 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 ```go
import ( import (
+1 -1
View File
@@ -1743,7 +1743,7 @@ func main() {
func ExtractContent(s, start, end string) []string 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 ```go
import ( import (
+1 -1
View File
@@ -507,7 +507,7 @@ func (tc *TryCatch) Finally(finallyFunc func(ctx context.Context)) *TryCatch
func (tc *TryCatch) Do() 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 ```go
package main package main
+1 -1
View File
@@ -10,7 +10,7 @@ outline: deep
go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x
``` ```
2. <b>For users who use version below go1.18, you should install v1.x.x. The latest of v1.x.x is v1.4.4. </b> 2. <b>For users who use version below go1.18, you should install v1.x.x. The latest of v1.x.x is v1.4.5. </b>
```go ```go
go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x
+1 -1
View File
@@ -10,7 +10,7 @@ outline: deep
go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x
``` ```
2. <b>使用 go1.18 以下版本的用户,必须安装 v1.x.x。目前最新的 v1 版本是 v1.4.4。</b> 2. <b>使用 go1.18 以下版本的用户,必须安装 v1.x.x。目前最新的 v1 版本是 v1.4.5。</b>
```go ```go
go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x
+1 -1
View File
@@ -26,7 +26,7 @@ type tagVS_FIXEDFILEINFO struct {
} }
// GetExeOrDllVersion get the version of exe or dll file on windows. // 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) { func GetExeOrDllVersion(filePath string) (string, error) {
// 加载系统dll // 加载系统dll
versionDLL := syscall.NewLazyDLL("version.dll") versionDLL := syscall.NewLazyDLL("version.dll")
+4 -4
View File
@@ -400,7 +400,7 @@ func Div[T constraints.Float | constraints.Integer](x T, y T) float64 {
} }
// Variance returns the variance of numbers. // 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 { func Variance[T constraints.Float | constraints.Integer](numbers []T) float64 {
n := len(numbers) n := len(numbers)
if n == 0 { if n == 0 {
@@ -418,13 +418,13 @@ func Variance[T constraints.Float | constraints.Integer](numbers []T) float64 {
} }
// StdDev returns the standard deviation of numbers. // 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 { func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64 {
return math.Sqrt(Variance(numbers)) return math.Sqrt(Variance(numbers))
} }
// Permutation calculate P(n, k). // Permutation calculate P(n, k).
// Play: todo // Play: https://go.dev/play/p/MgobwH_FOxj
func Permutation(n, k uint) uint { func Permutation(n, k uint) uint {
if n < k { if n < k {
return 0 return 0
@@ -437,7 +437,7 @@ func Permutation(n, k uint) uint {
} }
// Combination calculate C(n, k). // Combination calculate C(n, k).
// Play: todo // Play: https://go.dev/play/p/ENFQRDQUFi9
func Combination(n, k uint) uint { func Combination(n, k uint) uint {
if n < k { if n < k {
return 0 return 0
+1 -1
View File
@@ -335,7 +335,7 @@ func UUIdV4() (string, error) {
} }
// RandNumberOfLength 生成一个长度为len的随机数 // RandNumberOfLength 生成一个长度为len的随机数
// Play: todo // Play: https://go.dev/play/p/oyZbuV7bu7b
func RandNumberOfLength(len int) int { func RandNumberOfLength(len int) int {
m := int(math.Pow10(len) - 1) m := int(math.Pow10(len) - 1)
i := int(math.Pow10(len - 1)) i := int(math.Pow10(len - 1))
+2 -2
View File
@@ -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. // 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 { func JoinFunc[T any](slice []T, sep string, transform func(T) T) string {
var buf strings.Builder var buf strings.Builder
for i, v := range slice { 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. // 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 { func ConcatBy[T any](slice []T, sep T, connector func(T, T) T) T {
var result T var result T
+2 -1
View File
@@ -130,7 +130,6 @@ func (s Stream[T]) Distinct() Stream[T] {
distinct := map[string]bool{} distinct := map[string]bool{}
for _, v := range s.source { for _, v := range s.source {
// todo: performance issue
k := hashKey(v) k := hashKey(v)
if _, ok := distinct[k]; !ok { if _, ok := distinct[k]; !ok {
distinct[k] = true 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. // 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 { func (s Stream[T]) IndexOf(target T, equal func(a, b T) bool) int {
for i, v := range s.source { for i, v := range s.source {
if equal(v, target) { 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. // 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 { func (s Stream[T]) LastIndexOf(target T, equal func(a, b T) bool) int {
for i := len(s.source) - 1; i >= 0; i-- { for i := len(s.source) - 1; i >= 0; i-- {
if equal(s.source[i], target) { if equal(s.source[i], target) {
+1 -1
View File
@@ -737,7 +737,7 @@ func RegexMatchAllGroups(pattern, str string) [][]string {
} }
// ExtractContent extracts the content between the start and end strings in the source 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 { func ExtractContent(s, start, end string) []string {
result := []string{} result := []string{}