mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-17 03:02:28 +08:00
doc: update go playground demo
This commit is contained in:
19
README.md
19
README.md
@@ -272,7 +272,7 @@ import "github.com/duke-git/lancet/v2/convertor"
|
|||||||
[[play](https://go.dev/play/p/j4DP5dquxnk)]
|
[[play](https://go.dev/play/p/j4DP5dquxnk)]
|
||||||
- **<big>CopyProperties</big>** : copies each field from the source struct into the destination struct.
|
- **<big>CopyProperties</big>** : copies each field from the source struct into the destination struct.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor.md#CopyProperties)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor.md#CopyProperties)]
|
||||||
[[play](https://go.dev/play/p/FOVY3XJL-6B)]
|
[[play](https://go.dev/play/p/oZujoB5Sgg5)]
|
||||||
|
|
||||||
### 6. Cryptor package is for data encryption and decryption.
|
### 6. Cryptor package is for data encryption and decryption.
|
||||||
|
|
||||||
@@ -567,14 +567,20 @@ import "github.com/duke-git/lancet/v2/fileutil"
|
|||||||
[[play](https://go.dev/play/p/s74a9iBGcSw)]
|
[[play](https://go.dev/play/p/s74a9iBGcSw)]
|
||||||
- **<big>IsZipFile</big>** : checks if file is zip file or not.
|
- **<big>IsZipFile</big>** : checks if file is zip file or not.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#IsZipFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#IsZipFile)]
|
||||||
|
[[play](https://go.dev/play/p/9M0g2j_uF_e)]
|
||||||
- **<big>FileSize</big>** : return file size in bytes.
|
- **<big>FileSize</big>** : return file size in bytes.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#FileSize)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#FileSize)]
|
||||||
|
[[play](https://go.dev/play/p/H9Z05uD-Jjc)]
|
||||||
- **<big>MTime</big>** : return file modified time(unix timestamp).
|
- **<big>MTime</big>** : return file modified time(unix timestamp).
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#MTime)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#MTime)]
|
||||||
|
[[play](https://go.dev/play/p/s_Tl7lZoAaY)]
|
||||||
- **<big>Sha</big>** : return file sha value.
|
- **<big>Sha</big>** : return file sha value.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#Sha)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#Sha)]
|
||||||
|
[[play](https://go.dev/play/p/VfEEcO2MJYf)]
|
||||||
- **<big>ReadCsvFile</big>** : read file content into slice.
|
- **<big>ReadCsvFile</big>** : read file content into slice.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#ReadCsvFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#ReadCsvFile)]
|
||||||
|
[[play](https://go.dev/play/p/OExTkhGEd3_u)]
|
||||||
|
|
||||||
|
|
||||||
### 10. Formatter contains some functions for data formatting.
|
### 10. Formatter contains some functions for data formatting.
|
||||||
|
|
||||||
@@ -845,8 +851,10 @@ import "github.com/duke-git/lancet/v2/netutil"
|
|||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil.md#UploadFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil.md#UploadFile)]
|
||||||
- **<big>IsPingConnected</big>** : checks if can ping the specified host or not.
|
- **<big>IsPingConnected</big>** : checks if can ping the specified host or not.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil.md#IsPingConnected)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil.md#IsPingConnected)]
|
||||||
|
[[play](https://go.dev/play/p/q8OzTijsA87)]
|
||||||
- **<big>IsTelnetConnected</big>** : checks if can if can telnet the specified host or not.
|
- **<big>IsTelnetConnected</big>** : checks if can if can telnet the specified host or not.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil.md#IsTelnetConnected)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil.md#IsTelnetConnected)]
|
||||||
|
[[play](https://go.dev/play/p/yiLCGtQv_ZG)]
|
||||||
|
|
||||||
### 15. Random package implements some basic functions to generate random int and string.
|
### 15. Random package implements some basic functions to generate random int and string.
|
||||||
|
|
||||||
@@ -984,11 +992,13 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/CBKeBoHVLgq)]
|
[[play](https://go.dev/play/p/CBKeBoHVLgq)]
|
||||||
- **<big>FindBy</big>** : iterates over elements of slice, returning the first one that passes a truth test on predicate function.
|
- **<big>FindBy</big>** : iterates over elements of slice, returning the first one that passes a truth test on predicate function.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FindBy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FindBy)]
|
||||||
|
[[play](https://go.dev/play/p/n1lysBYl-GB)]
|
||||||
- **<big>FindLast<sup>deprecated</sup></big>** : return the last item that passes a truth test on predicate function.
|
- **<big>FindLast<sup>deprecated</sup></big>** : return the last item that passes a truth test on predicate function.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FindLast)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FindLast)]
|
||||||
[[play](https://go.dev/play/p/FFDPV_j7URd)]
|
[[play](https://go.dev/play/p/FFDPV_j7URd)]
|
||||||
- **<big>FindLastBy</big>** : iterates over elements of slice, returning the last one that passes a truth test on predicate function.
|
- **<big>FindLastBy</big>** : iterates over elements of slice, returning the last one that passes a truth test on predicate function.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FindLastBy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FindLastBy)]
|
||||||
|
[[play](https://go.dev/play/p/8iqomzyCl_s)]
|
||||||
- **<big>Flatten</big>** : flattens slice one level.
|
- **<big>Flatten</big>** : flattens slice one level.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Flatten)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Flatten)]
|
||||||
[[play](https://go.dev/play/p/hYa3cBEevtm)]
|
[[play](https://go.dev/play/p/hYa3cBEevtm)]
|
||||||
@@ -1314,16 +1324,23 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
[[play](https://go.dev/play/p/og47F5x_jTZ)]
|
[[play](https://go.dev/play/p/og47F5x_jTZ)]
|
||||||
- **<big>StringToBytes</big>** : converts a string to byte slice without a memory allocation.
|
- **<big>StringToBytes</big>** : converts a string to byte slice without a memory allocation.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#StringToBytes)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#StringToBytes)]
|
||||||
|
[[play](https://go.dev/play/p/7OyFBrf9AxA)]
|
||||||
- **<big>BytesToString</big>** : converts a byte slice to string without a memory allocation.
|
- **<big>BytesToString</big>** : converts a byte slice to string without a memory allocation.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#BytesToString)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#BytesToString)]
|
||||||
|
[[play](https://go.dev/play/p/6c68HRvJecH)]
|
||||||
- **<big>IsBlank</big>** : checks if a string is whitespace or empty.
|
- **<big>IsBlank</big>** : checks if a string is whitespace or empty.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#IsBlank)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#IsBlank)]
|
||||||
|
[[play](https://go.dev/play/p/6zXRH_c0Qd3)]
|
||||||
- **<big>HasPrefixAny</big>** : checks if a string starts with any of an array of specified strings.
|
- **<big>HasPrefixAny</big>** : checks if a string starts with any of an array of specified strings.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#HasPrefixAny)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#HasPrefixAny)]
|
||||||
|
[[play](https://go.dev/play/p/8UUTl2C5slo)]
|
||||||
- **<big>HasSuffixAny</big>** : checks if a string ends with any of an array of specified strings.
|
- **<big>HasSuffixAny</big>** : checks if a string ends with any of an array of specified strings.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#HasSuffixAny)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#HasSuffixAny)]
|
||||||
|
[[play](https://go.dev/play/p/sKWpCQdOVkx)]
|
||||||
- **<big>IndexOffset</big>** : returns the index of the first instance of substr in string after offsetting the string by `idxFrom`.
|
- **<big>IndexOffset</big>** : returns the index of the first instance of substr in string after offsetting the string by `idxFrom`.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#IndexOffset)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#IndexOffset)]
|
||||||
|
[[play](https://go.dev/play/p/qZo4lV2fomB)]
|
||||||
|
|
||||||
|
|
||||||
### 21. System package contain some functions about os, runtime, shell command.
|
### 21. System package contain some functions about os, runtime, shell command.
|
||||||
|
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ import "github.com/duke-git/lancet/v2/convertor"
|
|||||||
[[play](https://go.dev/play/p/j4DP5dquxnk)]
|
[[play](https://go.dev/play/p/j4DP5dquxnk)]
|
||||||
- **<big>CopyProperties</big>** : 拷贝不同结构体之间的同名字段。
|
- **<big>CopyProperties</big>** : 拷贝不同结构体之间的同名字段。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor_zh-CN.md#CopyProperties)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor_zh-CN.md#CopyProperties)]
|
||||||
[[play](https://go.dev/play/p/FOVY3XJL-6B)]
|
[[play](https://go.dev/play/p/oZujoB5Sgg5)]
|
||||||
|
|
||||||
### 6. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。
|
### 6. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。
|
||||||
|
|
||||||
@@ -566,14 +566,20 @@ import "github.com/duke-git/lancet/v2/fileutil"
|
|||||||
[[play](https://go.dev/play/p/s74a9iBGcSw)]
|
[[play](https://go.dev/play/p/s74a9iBGcSw)]
|
||||||
- **<big>IsZipFile</big>** : 判断文件是否是zip压缩文件。
|
- **<big>IsZipFile</big>** : 判断文件是否是zip压缩文件。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#IsZipFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#IsZipFile)]
|
||||||
|
[[play](https://go.dev/play/p/9M0g2j_uF_e)]
|
||||||
- **<big>FileSize</big>** : 返回文件字节大小。
|
- **<big>FileSize</big>** : 返回文件字节大小。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#FileSize)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#FileSize)]
|
||||||
|
[[play](https://go.dev/play/p/H9Z05uD-Jjc)]
|
||||||
- **<big>MTime</big>** : 返回文件修改时间(unix timestamp)。
|
- **<big>MTime</big>** : 返回文件修改时间(unix timestamp)。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#MTime)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#MTime)]
|
||||||
|
[[play](https://go.dev/play/p/s_Tl7lZoAaY)]
|
||||||
- **<big>Sha</big>** : 返回文件sha值。
|
- **<big>Sha</big>** : 返回文件sha值。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#Sha)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#Sha)]
|
||||||
|
[[play](https://go.dev/play/p/VfEEcO2MJYf)]
|
||||||
- **<big>ReadCsvFile</big>** : 读取csv文件内容到切片。
|
- **<big>ReadCsvFile</big>** : 读取csv文件内容到切片。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#ReadCsvFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#ReadCsvFile)]
|
||||||
|
[[play](https://go.dev/play/p/OExTkhGEd3_u)]
|
||||||
|
|
||||||
|
|
||||||
### 10. formatter 格式化器包含一些数据格式化处理方法。
|
### 10. formatter 格式化器包含一些数据格式化处理方法。
|
||||||
|
|
||||||
@@ -844,8 +850,10 @@ import "github.com/duke-git/lancet/v2/netutil"
|
|||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#UploadFile)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#UploadFile)]
|
||||||
- **<big>IsPingConnected</big>** : 检查能否ping通主机。
|
- **<big>IsPingConnected</big>** : 检查能否ping通主机。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#IsPingConnected)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#IsPingConnected)]
|
||||||
|
[[play](https://go.dev/play/p/q8OzTijsA87)]
|
||||||
- **<big>IsTelnetConnected</big>** : 检查能否telnet到主机。
|
- **<big>IsTelnetConnected</big>** : 检查能否telnet到主机。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#IsTelnetConnected)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/netutil_zh-CN.md#IsTelnetConnected)]
|
||||||
|
[[play](https://go.dev/play/p/yiLCGtQv_ZG)]
|
||||||
|
|
||||||
### 15. random 随机数生成器包,可以生成随机[]bytes, int, string。
|
### 15. random 随机数生成器包,可以生成随机[]bytes, int, string。
|
||||||
|
|
||||||
@@ -983,11 +991,13 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/CBKeBoHVLgq)]
|
[[play](https://go.dev/play/p/CBKeBoHVLgq)]
|
||||||
- **<big>FindBy</big>** : 遍历切片的元素,返回第一个通过 predicate 函数真值测试的元素。
|
- **<big>FindBy</big>** : 遍历切片的元素,返回第一个通过 predicate 函数真值测试的元素。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindBy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindBy)]
|
||||||
|
[[play](https://go.dev/play/p/n1lysBYl-GB)]
|
||||||
- **<big>FindLast<sup>deprecated</sup></big>** : 从头到尾遍历 slice 的元素,返回最后一个通过 predicate 函数真值测试的元素。
|
- **<big>FindLast<sup>deprecated</sup></big>** : 从头到尾遍历 slice 的元素,返回最后一个通过 predicate 函数真值测试的元素。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindLast)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindLast)]
|
||||||
[[play](https://go.dev/play/p/FFDPV_j7URd)]
|
[[play](https://go.dev/play/p/FFDPV_j7URd)]
|
||||||
- **<big>FindLastBy</big>** : 从遍历slice的元素,返回最后一个通过predicate函数真值测试的元素。
|
- **<big>FindLastBy</big>** : 从遍历slice的元素,返回最后一个通过predicate函数真值测试的元素。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindLastBy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FindLastBy)]
|
||||||
|
[[play](https://go.dev/play/p/8iqomzyCl_s)]
|
||||||
- **<big>Flatten</big>** : 将多维切片展平一层。
|
- **<big>Flatten</big>** : 将多维切片展平一层。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Flatten)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Flatten)]
|
||||||
[[play](https://go.dev/play/p/hYa3cBEevtm)]
|
[[play](https://go.dev/play/p/hYa3cBEevtm)]
|
||||||
@@ -1316,16 +1326,22 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
[[play](https://go.dev/play/p/og47F5x_jTZ)]
|
[[play](https://go.dev/play/p/og47F5x_jTZ)]
|
||||||
- **<big>StringToBytes</big>** : 在不分配内存的情况下将字符串转换为字节片。
|
- **<big>StringToBytes</big>** : 在不分配内存的情况下将字符串转换为字节片。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#StringToBytes)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#StringToBytes)]
|
||||||
|
[[play](https://go.dev/play/p/7OyFBrf9AxA)]
|
||||||
- **<big>BytesToString</big>** : 在不分配内存的情况下将字节切片转换为字符串。
|
- **<big>BytesToString</big>** : 在不分配内存的情况下将字节切片转换为字符串。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#BytesToString)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#BytesToString)]
|
||||||
|
[[play](https://go.dev/play/p/6c68HRvJecH)]
|
||||||
- **<big>IsBlank</big>** : 检查字符串是否为空格或空。
|
- **<big>IsBlank</big>** : 检查字符串是否为空格或空。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#IsBlank)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#IsBlank)]
|
||||||
|
[[play](https://go.dev/play/p/6zXRH_c0Qd3)]
|
||||||
- **<big>HasPrefixAny</big>** : 检查字符串是否以指定字符串数组中的任何一个开头。
|
- **<big>HasPrefixAny</big>** : 检查字符串是否以指定字符串数组中的任何一个开头。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#HasPrefixAny)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#HasPrefixAny)]
|
||||||
|
[[play](https://go.dev/play/p/8UUTl2C5slo)]
|
||||||
- **<big>HasSuffixAny</big>** : 检查字符串是否以指定字符串数组中的任何一个结尾。
|
- **<big>HasSuffixAny</big>** : 检查字符串是否以指定字符串数组中的任何一个结尾。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#HasSuffixAny)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#HasSuffixAny)]
|
||||||
|
[[play](https://go.dev/play/p/sKWpCQdOVkx)]
|
||||||
- **<big>IndexOffset</big>** : 将字符串偏移idxFrom后,返回字符串中第一个 substr 实例的索引。
|
- **<big>IndexOffset</big>** : 将字符串偏移idxFrom后,返回字符串中第一个 substr 实例的索引。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#IndexOffset)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#IndexOffset)]
|
||||||
|
[[play](https://go.dev/play/p/qZo4lV2fomB)]
|
||||||
|
|
||||||
### 21. system 包含 os, runtime, shell command 的相关函数。
|
### 21. system 包含 os, runtime, shell command 的相关函数。
|
||||||
|
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ func DeepClone[T any](src T) T {
|
|||||||
|
|
||||||
// CopyProperties copies each field from the source into the destination. It recursively copies struct pointers and interfaces that contain struct pointers.
|
// CopyProperties copies each field from the source into the destination. It recursively copies struct pointers and interfaces that contain struct pointers.
|
||||||
// use json.Marshal/Unmarshal, so json tag should be set for fields of dst and src struct.
|
// use json.Marshal/Unmarshal, so json tag should be set for fields of dst and src struct.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/oZujoB5Sgg5
|
||||||
func CopyProperties[T, U any](dst T, src U) error {
|
func CopyProperties[T, U any](dst T, src U) error {
|
||||||
dstType, srcType := reflect.TypeOf(dst), reflect.TypeOf(src)
|
dstType, srcType := reflect.TypeOf(dst), reflect.TypeOf(src)
|
||||||
|
|
||||||
|
|||||||
@@ -757,7 +757,11 @@ func main() {
|
|||||||
|
|
||||||
indicatorVO := IndicatorVO{}
|
indicatorVO := IndicatorVO{}
|
||||||
|
|
||||||
CopyProperties(&indicatorVO, indicator)
|
err := convertor.CopyProperties(&indicatorVO, indicator)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(indicatorVO.Id)
|
fmt.Println(indicatorVO.Id)
|
||||||
fmt.Println(indicatorVO.Ip)
|
fmt.Println(indicatorVO.Ip)
|
||||||
|
|||||||
@@ -756,7 +756,11 @@ func main() {
|
|||||||
|
|
||||||
indicatorVO := IndicatorVO{}
|
indicatorVO := IndicatorVO{}
|
||||||
|
|
||||||
CopyProperties(&indicatorVO, indicator)
|
err := convertor.CopyProperties(&indicatorVO, indicator)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(indicatorVO.Id)
|
fmt.Println(indicatorVO.Id)
|
||||||
fmt.Println(indicatorVO.Ip)
|
fmt.Println(indicatorVO.Ip)
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
isZip := IsZipFile("./zipfile.zip")
|
isZip := fileutil.IsZipFile("./zipfile.zip")
|
||||||
fmt.Println(isZip)
|
fmt.Println(isZip)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
isZip := IsZipFile("./zipfile.zip")
|
isZip := fileutil.IsZipFile("./zipfile.zip")
|
||||||
fmt.Println(isZip)
|
fmt.Println(isZip)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -922,7 +922,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := DownloadFile("./lancet_logo.jpg", "https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b")
|
err := netutil.DownloadFile("./lancet_logo.jpg", "https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b")
|
||||||
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -924,7 +924,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := DownloadFile("./lancet_logo.jpg", "https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b")
|
err := netutil.DownloadFile("./lancet_logo.jpg", "https://picx.zhimg.com/v2-fc82a4199749de9cfb71e32e54f489d3_720w.jpg?source=172ae18b")
|
||||||
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -968,6 +968,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// hello world
|
// hello world
|
||||||
// 你好😄
|
// 你好😄
|
||||||
@@ -998,6 +999,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// [97 98 99]
|
// [97 98 99]
|
||||||
// true
|
// true
|
||||||
@@ -1027,6 +1029,7 @@ func main() {
|
|||||||
result := strutil.BytesToString(bytes)
|
result := strutil.BytesToString(bytes)
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// abc
|
// abc
|
||||||
}
|
}
|
||||||
@@ -1058,6 +1061,7 @@ func main() {
|
|||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// true
|
// true
|
||||||
@@ -1089,6 +1093,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
@@ -1119,6 +1124,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
@@ -1157,6 +1163,7 @@ func main() {
|
|||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 12
|
// 12
|
||||||
// 1
|
// 1
|
||||||
|
|||||||
@@ -968,6 +968,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// hello world
|
// hello world
|
||||||
// 你好😄
|
// 你好😄
|
||||||
@@ -1027,6 +1028,7 @@ func main() {
|
|||||||
result := strutil.BytesToString(bytes)
|
result := strutil.BytesToString(bytes)
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// abc
|
// abc
|
||||||
}
|
}
|
||||||
@@ -1058,6 +1060,7 @@ func main() {
|
|||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// true
|
// true
|
||||||
@@ -1089,6 +1092,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
@@ -1119,6 +1123,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
@@ -1157,6 +1162,7 @@ func main() {
|
|||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 12
|
// 12
|
||||||
// 1
|
// 1
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ func ListFileNames(path string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsZipFile checks if file is zip or not.
|
// IsZipFile checks if file is zip or not.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/9M0g2j_uF_e
|
||||||
func IsZipFile(filepath string) bool {
|
func IsZipFile(filepath string) bool {
|
||||||
f, err := os.Open(filepath)
|
f, err := os.Open(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -383,7 +383,7 @@ func CurrentPath() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FileSize returns file size in bytes.
|
// FileSize returns file size in bytes.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/H9Z05uD-Jjc
|
||||||
func FileSize(path string) (int64, error) {
|
func FileSize(path string) (int64, error) {
|
||||||
f, err := os.Stat(path)
|
f, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -393,7 +393,7 @@ func FileSize(path string) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MTime returns file modified time.
|
// MTime returns file modified time.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/s_Tl7lZoAaY
|
||||||
func MTime(filepath string) (int64, error) {
|
func MTime(filepath string) (int64, error) {
|
||||||
f, err := os.Stat(filepath)
|
f, err := os.Stat(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -403,7 +403,7 @@ func MTime(filepath string) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MTime returns file sha value, param `shaType` should be 1, 256 or 512.
|
// MTime returns file sha value, param `shaType` should be 1, 256 or 512.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/VfEEcO2MJYf
|
||||||
func Sha(filepath string, shaType ...int) (string, error) {
|
func Sha(filepath string, shaType ...int) (string, error) {
|
||||||
file, err := os.Open(filepath)
|
file, err := os.Open(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -437,7 +437,7 @@ func Sha(filepath string, shaType ...int) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadCsvFile read file content into slice.
|
// ReadCsvFile read file content into slice.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/OExTkhGEd3_u
|
||||||
func ReadCsvFile(filepath string) ([][]string, error) {
|
func ReadCsvFile(filepath string) ([][]string, error) {
|
||||||
f, err := os.Open(filepath)
|
f, err := os.Open(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ func DownloadFile(filepath string, url string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsPingConnected checks if can ping specified host or not.
|
// IsPingConnected checks if can ping specified host or not.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/q8OzTijsA87
|
||||||
func IsPingConnected(host string) bool {
|
func IsPingConnected(host string) bool {
|
||||||
cmd := exec.Command("ping", host, "-c", "4", "-W", "6")
|
cmd := exec.Command("ping", host, "-c", "4", "-W", "6")
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ func IsPingConnected(host string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsTelnetConnected checks if can telnet specified host or not.
|
// IsTelnetConnected checks if can telnet specified host or not.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/yiLCGtQv_ZG
|
||||||
func IsTelnetConnected(host string, port string) bool {
|
func IsTelnetConnected(host string, port string) bool {
|
||||||
adder := host + ":" + port
|
adder := host + ":" + port
|
||||||
conn, err := net.DialTimeout("tcp", adder, 5*time.Second)
|
conn, err := net.DialTimeout("tcp", adder, 5*time.Second)
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, boo
|
|||||||
// FindBy iterates over elements of slice, returning the first one that passes a truth test on predicate function.
|
// FindBy iterates over elements of slice, returning the first one that passes a truth test on predicate function.
|
||||||
// If return T is nil or zero value then no items matched the predicate func.
|
// If return T is nil or zero value then no items matched the predicate func.
|
||||||
// In contrast to Find or FindLast, its return value no longer requires dereferencing
|
// In contrast to Find or FindLast, its return value no longer requires dereferencing
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/n1lysBYl-GB
|
||||||
func FindBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool) {
|
func FindBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool) {
|
||||||
index := -1
|
index := -1
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ func FindBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok b
|
|||||||
// FindLastBy iterates over elements of slice, returning the last one that passes a truth test on predicate function.
|
// FindLastBy iterates over elements of slice, returning the last one that passes a truth test on predicate function.
|
||||||
// If return T is nil or zero value then no items matched the predicate func.
|
// If return T is nil or zero value then no items matched the predicate func.
|
||||||
// In contrast to Find or FindLast, its return value no longer requires dereferencing
|
// In contrast to Find or FindLast, its return value no longer requires dereferencing
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/8iqomzyCl_s
|
||||||
func FindLastBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool) {
|
func FindLastBy[T any](slice []T, predicate func(index int, item T) bool) (v T, ok bool) {
|
||||||
index := -1
|
index := -1
|
||||||
|
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ func RemoveNonPrintable(str string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StringToBytes converts a string to byte slice without a memory allocation.
|
// StringToBytes converts a string to byte slice without a memory allocation.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/7OyFBrf9AxA
|
||||||
func StringToBytes(str string) (b []byte) {
|
func StringToBytes(str string) (b []byte) {
|
||||||
sh := *(*reflect.StringHeader)(unsafe.Pointer(&str))
|
sh := *(*reflect.StringHeader)(unsafe.Pointer(&str))
|
||||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||||
@@ -386,13 +386,13 @@ func StringToBytes(str string) (b []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BytesToString converts a byte slice to string without a memory allocation.
|
// BytesToString converts a byte slice to string without a memory allocation.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/6c68HRvJecH
|
||||||
func BytesToString(bytes []byte) string {
|
func BytesToString(bytes []byte) string {
|
||||||
return *(*string)(unsafe.Pointer(&bytes))
|
return *(*string)(unsafe.Pointer(&bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsBlank checks if a string is whitespace, empty.
|
// IsBlank checks if a string is whitespace, empty.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/6zXRH_c0Qd3
|
||||||
func IsBlank(str string) bool {
|
func IsBlank(str string) bool {
|
||||||
if len(str) == 0 {
|
if len(str) == 0 {
|
||||||
return true
|
return true
|
||||||
@@ -408,7 +408,7 @@ func IsBlank(str string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasPrefixAny check if a string starts with any of an array of specified strings.
|
// HasPrefixAny check if a string starts with any of an array of specified strings.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/8UUTl2C5slo
|
||||||
func HasPrefixAny(str string, prefixes []string) bool {
|
func HasPrefixAny(str string, prefixes []string) bool {
|
||||||
if len(str) == 0 || len(prefixes) == 0 {
|
if len(str) == 0 || len(prefixes) == 0 {
|
||||||
return false
|
return false
|
||||||
@@ -422,7 +422,7 @@ func HasPrefixAny(str string, prefixes []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasSuffixAny check if a string ends with any of an array of specified strings.
|
// HasSuffixAny check if a string ends with any of an array of specified strings.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/sKWpCQdOVkx
|
||||||
func HasSuffixAny(str string, suffixes []string) bool {
|
func HasSuffixAny(str string, suffixes []string) bool {
|
||||||
if len(str) == 0 || len(suffixes) == 0 {
|
if len(str) == 0 || len(suffixes) == 0 {
|
||||||
return false
|
return false
|
||||||
@@ -437,7 +437,7 @@ func HasSuffixAny(str string, suffixes []string) bool {
|
|||||||
|
|
||||||
// IndexOffset returns the index of the first instance of substr in string after offsetting the string by `idxFrom`,
|
// IndexOffset returns the index of the first instance of substr in string after offsetting the string by `idxFrom`,
|
||||||
// or -1 if substr is not present in string.
|
// or -1 if substr is not present in string.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/qZo4lV2fomB
|
||||||
func IndexOffset(str string, substr string, idxFrom int) int {
|
func IndexOffset(str string, substr string, idxFrom int) int {
|
||||||
if idxFrom > len(str)-1 || idxFrom < 0 {
|
if idxFrom > len(str)-1 || idxFrom < 0 {
|
||||||
return -1
|
return -1
|
||||||
|
|||||||
Reference in New Issue
Block a user