From 1b31014f8176011af279d7b5994a7b47ac857b37 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 6 Mar 2024 14:52:35 +0800 Subject: [PATCH] doc: add go playground demo --- README.md | 17 +++++++++++++++-- README_zh-CN.md | 16 ++++++++++++++-- convertor/convertor.go | 4 ++++ docs/api/packages/convertor.md | 16 ++++++++-------- docs/api/packages/fileutil.md | 4 ++-- docs/api/packages/mathutil.md | 17 +++++++++-------- docs/api/packages/strutil.md | 6 +++--- docs/en/api/packages/convertor.md | 16 ++++++++-------- docs/en/api/packages/fileutil.md | 6 +++--- docs/en/api/packages/mathutil.md | 16 ++++++++-------- docs/en/api/packages/strutil.md | 6 +++--- fileutil/file.go | 4 ++-- mathutil/mathutil.go | 10 +++++----- strutil/string.go | 4 ++-- 14 files changed, 86 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 283a037..a0f6167 100644 --- a/README.md +++ b/README.md @@ -660,9 +660,12 @@ import "github.com/duke-git/lancet/v2/fileutil" - **CreateDir** : create directory in absolute path. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#CreateDir)] [[play](https://go.dev/play/p/qUuCe1OGQnM)] -- **CopyFile** :copy src file to dest file. +- **CopyFile** : copy src file to dest file. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#CopyFile)] [[play](https://go.dev/play/p/Jg9AMJMLrJi)] +- **CopyDir** : copy src directory to dest directory. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#CopyDir)] + [[play](https://go.dev/play/p/YAyFTA_UuPb)] - **FileMode** : return file's mode and permission. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#FileMode)] [[play](https://go.dev/play/p/2l2hI42fA3p)] @@ -731,8 +734,10 @@ import "github.com/duke-git/lancet/v2/fileutil" [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#ReadFile)] - **ChunkRead** : reads a block from the file at the specified offset and returns all lines within the block. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/fileutil.md#ChunkRead)] + [[play](https://go.dev/play/p/r0hPmKWhsgf)] - **ParallelChunkRead** : 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)]

10. Formatter contains some functions for data formatting.        index

@@ -959,12 +964,16 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/aumarSHIGzP)] - **CeilToFloat** : round float up n decimal places. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#CeilToFloat)] + [[play](https://go.dev/play/p/8hOeSADZPCo)] - **CeilToString** : round float up n decimal places, then conver to string. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#CeilToString)] + [[play](https://go.dev/play/p/wy5bYEyUKKG)] - **FloorToFloat** : round float down n decimal places. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#FloorToFloat)] + [[play](https://go.dev/play/p/vbCBrQHZEED)] - **FloorToString** : round float down n decimal places, then conver to string. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#FloorToString)] + [[play](https://go.dev/play/p/Qk9KPd2IdDb)] - **Range** : Creates a slice of numbers from start with specified count, element step is 1. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Range)] [[play](https://go.dev/play/p/9ke2opxa8ZP)] @@ -1006,6 +1015,7 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/fsyBh1Os-1d)] - **Div** : returns the result of x divided by y. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/mathutil.md#Div)] + [[play](https://go.dev/play/p/WLxDdGXXYat)]

14. Netutil package contains functions to get net information and send http request.        index

@@ -1660,8 +1670,11 @@ import "github.com/duke-git/lancet/v2/strutil" [[play](https://go.dev/play/p/HzLC9vsTwkf)] - **SubInBetween** : return substring between the start and end position(excluded) of source string. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#SubInBetween)] + [[play](https://go.dev/play/p/EDbaRvjeNsv)] - **HammingDistance** : calculates the Hamming distance between two strings. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#HammingDistance)] + [[play](https://go.dev/play/p/glNdQEA9HUi)] +

22. System package contain some functions about os, runtime, shell command.        index

diff --git a/README_zh-CN.md b/README_zh-CN.md index 90a7f2a..a36d0e1 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -659,9 +659,12 @@ import "github.com/duke-git/lancet/v2/fileutil" - **CreateDir** : 创建嵌套目录,例如/a/, /a/b/。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#CreateDir)] [[play](https://go.dev/play/p/qUuCe1OGQnM)] -- **CopyFile** :拷贝文件,会覆盖原有的文件。 +- **CopyFile** : 拷贝文件,会覆盖原有的文件。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#CopyFile)] [[play](https://go.dev/play/p/Jg9AMJMLrJi)] +- **CopyDir** : 拷贝目录。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#CopyDir)] + [[play](https://go.dev/play/p/YAyFTA_UuPb)] - **FileMode** : 获取文件 mode 信息。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#FileMode)] [[play](https://go.dev/play/p/2l2hI42fA3p)] @@ -730,8 +733,10 @@ import "github.com/duke-git/lancet/v2/fileutil" [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ReadFile)] - **ChunkRead** : 从文件的指定偏移读取块并返回块内所有行。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ChunkRead)] + [[play](https://go.dev/play/p/r0hPmKWhsgf)] - **ParallelChunkRead** : 并行读取文件并将每个块的行发送到指定通道。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/fileutil.md#ParallelChunkRead)] + [[play](https://go.dev/play/p/teMXnCsdSEw)] @@ -960,12 +965,16 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/aumarSHIGzP)] - **CeilToFloat** : 向上舍入(进一法),保留n位小数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#CeilToFloat)] + [[play](https://go.dev/play/p/8hOeSADZPCo)] - **CeilToString** : 向上舍入(进一法),保留n位小数,返回字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#CeilToString)] + [[play](https://go.dev/play/p/wy5bYEyUKKG)] - **FloorToFloat** : 向下舍入(去尾法),保留n位小数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#FloorToFloat)] + [[play](https://go.dev/play/p/vbCBrQHZEED)] - **FloorToString** : 向下舍入(去尾法),保留n位小数,返回字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#FloorToString)] + [[play](https://go.dev/play/p/Qk9KPd2IdDb)] - **Range** : 根据指定的起始值和数量,创建一个数字切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Range)] [[play](https://go.dev/play/p/9ke2opxa8ZP)] @@ -1007,7 +1016,7 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/fsyBh1Os-1d)] - **Div** : 除法运算。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/mathutil.md#Div)] - + [[play](https://go.dev/play/p/WLxDdGXXYat)]

14. netutil 网络包支持获取 ip 地址,发送 http 请求。       回到目录

@@ -1663,8 +1672,11 @@ import "github.com/duke-git/lancet/v2/strutil" [[play](https://go.dev/play/p/HzLC9vsTwkf)] - **SubInBetween** : 获取字符串中指定的起始字符串start和终止字符串end直接的子字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#SubInBetween)] + [[play](https://go.dev/play/p/EDbaRvjeNsv)] - **HammingDistance** : 计算两个字符串之间的汉明距离。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#HammingDistance)] + [[play](https://go.dev/play/p/glNdQEA9HUi)] +

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

diff --git a/convertor/convertor.go b/convertor/convertor.go index 1dcca55..423df3b 100644 --- a/convertor/convertor.go +++ b/convertor/convertor.go @@ -397,6 +397,7 @@ func GbkToUtf8(bs []byte) ([]byte, error) { } // ToStdBase64 convert data to standard base64 encoding. +// Play: https://go.dev/play/p/_fLJqJD3NMo func ToStdBase64(value any) string { if value == nil || (reflect.ValueOf(value).Kind() == reflect.Ptr && reflect.ValueOf(value).IsNil()) { return "" @@ -418,6 +419,7 @@ func ToStdBase64(value any) string { } // ToUrlBase64 convert data to URL base64 encoding. +// Play: https://go.dev/play/p/C_d0GlvEeUR func ToUrlBase64(value any) string { if value == nil || (reflect.ValueOf(value).Kind() == reflect.Ptr && reflect.ValueOf(value).IsNil()) { return "" @@ -439,6 +441,7 @@ func ToUrlBase64(value any) string { } // ToRawStdBase64 convert data to raw standard base64 encoding. +// Play: https://go.dev/play/p/wSAr3sfkDcv func ToRawStdBase64(value any) string { if value == nil || (reflect.ValueOf(value).Kind() == reflect.Ptr && reflect.ValueOf(value).IsNil()) { return "" @@ -460,6 +463,7 @@ func ToRawStdBase64(value any) string { } // ToRawUrlBase64 convert data to raw URL base64 encoding. +// Play: https://go.dev/play/p/HwdDPFcza1O func ToRawUrlBase64(value any) string { if value == nil || (reflect.ValueOf(value).Kind() == reflect.Ptr && reflect.ValueOf(value).IsNil()) { return "" diff --git a/docs/api/packages/convertor.md b/docs/api/packages/convertor.md index 841c3b7..f32a080 100644 --- a/docs/api/packages/convertor.md +++ b/docs/api/packages/convertor.md @@ -891,7 +891,7 @@ func main() { func ToStdBase64(value any) string ``` -示例: +示例:[运行](https://go.dev/play/p/_fLJqJD3NMo) ```go package main @@ -963,7 +963,7 @@ func main() { func ToUrlBase64(value any) string ``` -示例: +示例:[运行](https://go.dev/play/p/C_d0GlvEeUR) ```go package main @@ -1032,7 +1032,7 @@ func main() { func ToRawStdBase64(value any) string ``` -示例: +示例:[运行](https://go.dev/play/p/wSAr3sfkDcv) ```go package main @@ -1064,7 +1064,7 @@ func main() { fmt.Println(afterEncode) floatVal := 123.456 - afterEncode = convertor.ToRawStdBase64(floatVal) + afterEncode := convertor.ToRawStdBase64(floatVal) fmt.Println(afterEncode) boolVal := true @@ -1090,7 +1090,7 @@ func main() {

值转换为 ToRawUrlBase64 编码的字符串。error 类型的数据也会把 error 的原因进行编码,复杂的结构会转为 JSON 格式的字符串

-函数签名: +函数签名:[运行](https://go.dev/play/p/HwdDPFcza1O) ```go func ToRawUrlBase64(value any) string @@ -1109,7 +1109,7 @@ import ( func main() { stringVal := "hello" - afterEncode = convertor.ToRawUrlBase64(stringVal) + afterEncode := convertor.ToRawUrlBase64(stringVal) fmt.Println(afterEncode) byteSliceVal := []byte("hello") @@ -1132,11 +1132,11 @@ func main() { fmt.Println(afterEncode) boolVal := true - afterEncode = convertor.ToRawStdBase64(boolVal) + afterEncode = convertor.ToRawUrlBase64(boolVal) fmt.Println(afterEncode) errVal := errors.New("err") - afterEncode = convertor.ToRawStdBase64(errVal) + afterEncode = convertor.ToRawUrlBase64(errVal) fmt.Println(afterEncode) // Output: diff --git a/docs/api/packages/fileutil.md b/docs/api/packages/fileutil.md index 830dfc0..129bbe0 100644 --- a/docs/api/packages/fileutil.md +++ b/docs/api/packages/fileutil.md @@ -976,7 +976,7 @@ func main() { func ChunkRead(file *os.File, offset int64, size int, bufPool *sync.Pool) ([]string, error) ``` -示例: +示例:[运行](https://go.dev/play/p/r0hPmKWhsgf) ```go package main @@ -1035,7 +1035,7 @@ func main() { func ParallelChunkRead(filePath string, linesCh chan<- []string, chunkSizeMB, maxGoroutine int) error ``` -示例: +示例:[运行](https://go.dev/play/p/teMXnCsdSEw) ```go package main diff --git a/docs/api/packages/mathutil.md b/docs/api/packages/mathutil.md index d0f0903..a75d73b 100644 --- a/docs/api/packages/mathutil.md +++ b/docs/api/packages/mathutil.md @@ -508,7 +508,7 @@ func main() { func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 ``` -示例: +示例:[运行](https://go.dev/play/p/8hOeSADZPCo) ```go package main @@ -544,7 +544,7 @@ func main() { func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string ``` -示例: +示例:[运行](https://go.dev/play/p/wy5bYEyUKKG) ```go package main @@ -577,10 +577,10 @@ func main() { 函数签名: ```go -func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string +func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 ``` -示例: +示例:[运行](https://go.dev/play/p/vbCBrQHZEED) ```go package main @@ -613,10 +613,10 @@ func main() { 函数签名: ```go -func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string +func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string ``` -示例: +示例:[运行](https://go.dev/play/p/Qk9KPd2IdDb) ```go package main @@ -1130,7 +1130,7 @@ func main() { ### Div -

除法运算.

+

除法运算。

函数签名: @@ -1138,7 +1138,7 @@ func main() { func Div[T constraints.Float | constraints.Integer](x T, y T) float64 ``` -示例: +示例:[运行](https://go.dev/play/p/WLxDdGXXYat) ```go package main @@ -1156,6 +1156,7 @@ func main() { fmt.Println(result1) fmt.Println(result2) fmt.Println(result3) + // Output: // 2.25 // 0.5 diff --git a/docs/api/packages/strutil.md b/docs/api/packages/strutil.md index 95f190d..ad032f5 100644 --- a/docs/api/packages/strutil.md +++ b/docs/api/packages/strutil.md @@ -1475,7 +1475,7 @@ func main() { func SubInBetween(str string, start string, end string) string ``` -示例: +示例:[运行](https://go.dev/play/p/EDbaRvjeNsv) ```go import ( @@ -1505,10 +1505,10 @@ func main() { 函数签名: ```go -HammingDistance(a, b string) (int, error) +func HammingDistance(a, b string) (int, error) ``` -示例: +示例:[运行](https://go.dev/play/p/glNdQEA9HUi) ```go import ( diff --git a/docs/en/api/packages/convertor.md b/docs/en/api/packages/convertor.md index d61a4f3..33ffa9d 100644 --- a/docs/en/api/packages/convertor.md +++ b/docs/en/api/packages/convertor.md @@ -891,7 +891,7 @@ func main() { func ToStdBase64(value any) string ``` -Example: +Example:[Run](https://go.dev/play/p/_fLJqJD3NMo) ```go package main @@ -963,7 +963,7 @@ func main() { func ToUrlBase64(value any) string ``` -Example: +Example:[Run](https://go.dev/play/p/C_d0GlvEeUR) ```go package main @@ -1032,7 +1032,7 @@ func main() { func ToRawStdBase64(value any) string ``` -Example: +Example:[Run](https://go.dev/play/p/wSAr3sfkDcv) ```go package main @@ -1045,7 +1045,7 @@ import ( func main() { stringVal := "hello" - afterEncode = convertor.ToRawStdBase64(stringVal) + afterEncode := convertor.ToRawStdBase64(stringVal) fmt.Println(afterEncode) byteSliceVal := []byte("hello") @@ -1096,7 +1096,7 @@ func main() { func ToRawUrlBase64(value any) string ``` -Example: +Example:[Run](https://go.dev/play/p/HwdDPFcza1O) ```go package main @@ -1109,7 +1109,7 @@ import ( func main() { stringVal := "hello" - afterEncode = convertor.ToRawUrlBase64(stringVal) + afterEncode := convertor.ToRawUrlBase64(stringVal) fmt.Println(afterEncode) byteSliceVal := []byte("hello") @@ -1132,11 +1132,11 @@ func main() { fmt.Println(afterEncode) boolVal := true - afterEncode = convertor.ToRawStdBase64(boolVal) + afterEncode = convertor.ToRawUrlBase64(boolVal) fmt.Println(afterEncode) errVal := errors.New("err") - afterEncode = convertor.ToRawStdBase64(errVal) + afterEncode = convertor.ToRawUrlBase64(errVal) fmt.Println(afterEncode) // Output: diff --git a/docs/en/api/packages/fileutil.md b/docs/en/api/packages/fileutil.md index b4a449c..e572936 100644 --- a/docs/en/api/packages/fileutil.md +++ b/docs/en/api/packages/fileutil.md @@ -167,7 +167,7 @@ func main() { ### CopyDir -

copy src directory to dst directory, it will copy all files and directories recursively. the access permission will be the same as the source directory. if dstPath exists, it will return an error.

+

Copy src directory to dst directory, it will copy all files and directories recursively. the access permission will be the same as the source directory. if dstPath exists, it will return an error.

Signature: @@ -974,7 +974,7 @@ func main() { func ChunkRead(file *os.File, offset int64, size int, bufPool *sync.Pool) ([]string, error) ``` -Example: +Example:[Run](https://go.dev/play/p/r0hPmKWhsgf) ```go package main @@ -1033,7 +1033,7 @@ func main() { func ParallelChunkRead(filePath string, linesCh chan<- []string, chunkSizeMB, maxGoroutine int) error ``` -Example: +Example:[Run](https://go.dev/play/p/teMXnCsdSEw) ```go package main diff --git a/docs/en/api/packages/mathutil.md b/docs/en/api/packages/mathutil.md index 2e0e49a..3f4387f 100644 --- a/docs/en/api/packages/mathutil.md +++ b/docs/en/api/packages/mathutil.md @@ -508,7 +508,7 @@ func main() { func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 ``` -Example: +Example:[Run](https://go.dev/play/p/8hOeSADZPCo) ```go package main @@ -544,7 +544,7 @@ func main() { func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string ``` -Example: +Example:[Run](https://go.dev/play/p/wy5bYEyUKKG) ```go package main @@ -577,10 +577,10 @@ func main() { Signature: ```go -func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string +func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 ``` -Example: +Example:[Run](https://go.dev/play/p/vbCBrQHZEED) ```go package main @@ -613,10 +613,10 @@ func main() { Signature: ```go -func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string +func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string ``` -Example: +Example:[Run](https://go.dev/play/p/Qk9KPd2IdDb) ```go package main @@ -1130,7 +1130,7 @@ func main() { ### Div -

returns the result of x divided by y.

+

Returns the result of x divided by y.

Signature: @@ -1138,7 +1138,7 @@ func main() { func Div[T constraints.Float | constraints.Integer](x T, y T) float64 ``` -Example: +Example:[Run](https://go.dev/play/p/WLxDdGXXYat) ```go package main diff --git a/docs/en/api/packages/strutil.md b/docs/en/api/packages/strutil.md index 676a8bd..43b370e 100644 --- a/docs/en/api/packages/strutil.md +++ b/docs/en/api/packages/strutil.md @@ -1477,7 +1477,7 @@ func main() { func SubInBetween(str string, start string, end string) string ``` -Example: +Example:[运行](https://go.dev/play/p/EDbaRvjeNsv) ```go import ( @@ -1507,10 +1507,10 @@ func main() { Signature: ```go -HammingDistance(a, b string) (int, error) +func HammingDistance(a, b string) (int, error) ``` -Example: +Example:[运行](https://go.dev/play/p/glNdQEA9HUi) ```go import ( diff --git a/fileutil/file.go b/fileutil/file.go index 4e08d2b..052d0b2 100644 --- a/fileutil/file.go +++ b/fileutil/file.go @@ -869,7 +869,7 @@ func isCsvSupportedType(v interface{}) bool { } // ChunkRead reads a block from the file at the specified offset and returns all lines within the block -// Play: todo +// Play: https://go.dev/play/p/r0hPmKWhsgf func ChunkRead(file *os.File, offset int64, size int, bufPool *sync.Pool) ([]string, error) { buf := bufPool.Get().([]byte)[:size] // 从Pool获取缓冲区并调整大小 n, err := file.ReadAt(buf, offset) // 从指定偏移读取数据到缓冲区 @@ -901,7 +901,7 @@ func ChunkRead(file *os.File, offset int64, size int, bufPool *sync.Pool) ([]str // chunkSizeMB 分块的大小(单位MB,设置为0时使用默认100MB),设置过大反而不利,视情调整 // maxGoroutine 并发读取分块的数量,设置为0时使用CPU核心数 // linesCh用于接收返回结果的通道。 -// Play: todo +// Play: https://go.dev/play/p/teMXnCsdSEw func ParallelChunkRead(filePath string, linesCh chan<- []string, chunkSizeMB, maxGoroutine int) error { if chunkSizeMB == 0 { chunkSizeMB = 100 diff --git a/mathutil/mathutil.go b/mathutil/mathutil.go index 531a0c9..dc6b1b1 100644 --- a/mathutil/mathutil.go +++ b/mathutil/mathutil.go @@ -101,7 +101,7 @@ func TruncRound[T constraints.Float | constraints.Integer](x T, n int) T { } // FloorToFloat round down to n decimal places. -// Play: todo +// Play: https://go.dev/play/p/vbCBrQHZEED func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 { tmp := math.Pow(10.0, float64(n)) x *= T(tmp) @@ -110,7 +110,7 @@ func FloorToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 } // FloorToString round down to n decimal places. -// Play: todo +// Play: https://go.dev/play/p/Qk9KPd2IdDb func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string { tmp := math.Pow(10.0, float64(n)) x *= T(tmp) @@ -120,7 +120,7 @@ func FloorToString[T constraints.Float | constraints.Integer](x T, n int) string } // CeilToFloat round up to n decimal places. -// Play: todo +// Play: https://go.dev/play/p/8hOeSADZPCo func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 { tmp := math.Pow(10.0, float64(n)) x *= T(tmp) @@ -129,7 +129,7 @@ func CeilToFloat[T constraints.Float | constraints.Integer](x T, n int) float64 } // CeilToString round up to n decimal places. -// Play: todo +// Play: https://go.dev/play/p/wy5bYEyUKKG func CeilToString[T constraints.Float | constraints.Integer](x T, n int) string { tmp := math.Pow(10.0, float64(n)) x *= T(tmp) @@ -391,7 +391,7 @@ func Abs[T constraints.Integer | constraints.Float](x T) T { } // Div returns the result of x divided by y. -// Play: todo +// Play: https://go.dev/play/p/WLxDdGXXYat func Div[T constraints.Float | constraints.Integer](x T, y T) float64 { return float64(x) / float64(y) } diff --git a/strutil/string.go b/strutil/string.go index cda730c..e174ce9 100644 --- a/strutil/string.go +++ b/strutil/string.go @@ -585,7 +585,7 @@ func RemoveWhiteSpace(str string, repalceAll bool) string { } // SubInBetween return substring between the start and end position(excluded) of source string. -// Play: todo +// Play: https://go.dev/play/p/EDbaRvjeNsv func SubInBetween(str string, start string, end string) string { if _, after, ok := strings.Cut(str, start); ok { if before, _, ok := strings.Cut(after, end); ok { @@ -599,7 +599,7 @@ func SubInBetween(str string, start string, end string) string { // HammingDistance calculates the Hamming distance between two strings. // The Hamming distance is the number of positions at which the corresponding symbols are different. // This func returns an error if the input strings are of unequal lengths. -// Play: todo +// Play: https://go.dev/play/p/glNdQEA9HUi func HammingDistance(a, b string) (int, error) { if len(a) != len(b) { return -1, errors.New("a length and b length are unequal")