mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
Compare commits
64 Commits
5b6def5ff0
...
v2.2.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56c9327a86 | ||
|
|
11eb559998 | ||
|
|
61a612a06a | ||
|
|
2351ab4714 | ||
|
|
88eec858b4 | ||
|
|
14c37b5a5f | ||
|
|
ad8b1d424c | ||
|
|
a9f01d8a69 | ||
|
|
781b89d51a | ||
|
|
073c77e751 | ||
|
|
91a0d3077d | ||
|
|
17b34f8f19 | ||
|
|
8ff37f0eff | ||
|
|
f445ecbaf8 | ||
|
|
b698fec50f | ||
|
|
b38bb66b34 | ||
|
|
bdfdeaf496 | ||
|
|
172c44c07a | ||
|
|
534263eb08 | ||
|
|
a25b1ac7e3 | ||
|
|
d84f9777ea | ||
|
|
f9caaf8063 | ||
|
|
f198711d1c | ||
|
|
19378ca4d1 | ||
|
|
71c7733eb0 | ||
|
|
20786c360b | ||
|
|
51fafa110e | ||
|
|
07fc453b74 | ||
|
|
b309044981 | ||
|
|
541e6d4ea3 | ||
|
|
4037b96cc4 | ||
|
|
8e484c4a6f | ||
|
|
dd339563bc | ||
|
|
9567dcc57f | ||
|
|
de104ebeb6 | ||
|
|
eebd95395f | ||
|
|
56265647ff | ||
|
|
756da3719d | ||
|
|
f3008ac7c4 | ||
|
|
c6583d3b83 | ||
|
|
a3d7bac72e | ||
|
|
74b4d53514 | ||
|
|
a08afe0d77 | ||
|
|
ee680aa84c | ||
|
|
caa74064f0 | ||
|
|
abc94c0b26 | ||
|
|
86bcdce07b | ||
|
|
789f5d933d | ||
|
|
156fd2ef5d | ||
|
|
ea036b3a81 | ||
|
|
3daca8b331 | ||
|
|
21a952d2be | ||
|
|
03d331dfb6 | ||
|
|
ef79e1305e | ||
|
|
7c2670d019 | ||
|
|
31f64c0a98 | ||
|
|
28b8986cbe | ||
|
|
b4ff33ce80 | ||
|
|
25fa117712 | ||
|
|
0c9f539e3d | ||
|
|
05bd1afaa6 | ||
|
|
51cb665110 | ||
|
|
47c368e8f2 | ||
|
|
3127360b28 |
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
liberapay: Duke_Du
|
||||||
|
patreon: DukeDu
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,4 +11,5 @@ slice/testdata/*
|
|||||||
cryptor/*.pem
|
cryptor/*.pem
|
||||||
test
|
test
|
||||||
docs/node_modules
|
docs/node_modules
|
||||||
docs/.vitepress/cache
|
docs/.vitepress/cache
|
||||||
|
docs/.vitepress/dist
|
||||||
|
|||||||
37
CONTRIBUTING.en-US.md
Normal file
37
CONTRIBUTING.en-US.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Lancet Contributing Guide
|
||||||
|
|
||||||
|
Hi! Thank you for choosing Lancet.
|
||||||
|
|
||||||
|
Lancet is a powerful, efficient, and reusable util function library of go. It makes Go dev easier by taking the hassle out of working with concurrency, net, math, slice, string, etc.
|
||||||
|
|
||||||
|
We are excited that you are interested in contributing to lancet. Before submitting your contribution though, please make sure to take a moment and read through the following guidelines.
|
||||||
|
|
||||||
|
## Issue Guidelines
|
||||||
|
|
||||||
|
- Issues are exclusively for bug reports, feature requests and design-related topics. Other questions may be closed directly.
|
||||||
|
|
||||||
|
- Before submitting an issue, please check if similar problems have already been issued.
|
||||||
|
|
||||||
|
- Please specify which version of Lancet and Go you are using, and provide OS information. [Go Playground](https://go.dev/play/) is recommended to build a live demo so that your issue can be reproduced clearly.
|
||||||
|
|
||||||
|
## Pull Request Guidelines
|
||||||
|
|
||||||
|
- Fork this repository to your own account. Do not create branches here.
|
||||||
|
|
||||||
|
- Commit info should be formatted as `type(scope): info about commit`. eg. `fix(package): [scrollbar] fix xxx bug`.
|
||||||
|
|
||||||
|
1. type: type must be one of [chore, docs, feat, fix, refactor, release, test].
|
||||||
|
|
||||||
|
2. scope: scope must be one of [package, file, internal].
|
||||||
|
|
||||||
|
3. header: header must not be longer than 72 characters.
|
||||||
|
|
||||||
|
- Rebase before creating a PR to keep commit history clear.
|
||||||
|
|
||||||
|
- Before submitting a PR, please execute the unit test command: `go test -v ./...` to ensure that all unit test tasks should pass.
|
||||||
|
|
||||||
|
- Make sure PRs are created to `v2` branch instead of `master` branch.
|
||||||
|
|
||||||
|
- If your PR fixes a bug, please provide a description about the related bug.
|
||||||
|
|
||||||
|
- If the PR is for a new feature, make sure to complete the relevant documentation (/lancet/docs/en/api/packages).
|
||||||
37
CONTRIBUTING.zh-CN.md
Normal file
37
CONTRIBUTING.zh-CN.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Lancet 贡献指南
|
||||||
|
|
||||||
|
Hi! 首先感谢你使用 Lancet。
|
||||||
|
|
||||||
|
lancet(柳叶刀)是一个功能强大、全面、高效、可复用的go语言工具函数库。它消除了处理并发、网络、数学、切片、字符串等的麻烦,使 Go 开发变得更容易。
|
||||||
|
|
||||||
|
Lancet 的成长离不开大家的支持,如果你愿意为 Lancet 贡献代码或提供建议,请阅读以下内容。
|
||||||
|
|
||||||
|
## Issue 规范
|
||||||
|
|
||||||
|
- issue 仅用于提交 Bug 或 Feature 以及设计相关的内容,其它内容可能会被直接关闭。
|
||||||
|
|
||||||
|
- 在提交 issue 之前,请搜索相关内容是否已被提出。
|
||||||
|
|
||||||
|
- 请说明 Lancet 和 Go 的版本号,并提供操作系统信息。推荐使用 [Go Playground](https://go.dev/play/) 生成在线 demo,这能够更直观地重现问题。
|
||||||
|
|
||||||
|
## Pull Request 规范
|
||||||
|
|
||||||
|
- 请先 fork 一份到自己的项目下,不要直接在仓库下建分支。
|
||||||
|
|
||||||
|
- commit 信息要以 `type(scope): 描述信息` 的形式填写,例如 `fix(package): [scrollbar] fix xxx bug`。
|
||||||
|
|
||||||
|
1. type: 必须是 chore, docs, feat, fix, refactor, release, test 其中的一个。
|
||||||
|
|
||||||
|
2. scope: 必须是 package, file, internal 其中的一个。
|
||||||
|
|
||||||
|
3. header: 描述信息不要超过 72 个字符。
|
||||||
|
|
||||||
|
- 提交 PR 前请 rebase,确保 commit 记录的整洁。
|
||||||
|
|
||||||
|
- 提交 PR 前请执行单元测试命令:go test -v ./...,确保所有单元测试任务通过。
|
||||||
|
|
||||||
|
- 确保 PR 是提交到 `v2` 分支,而不是 `main` 分支。
|
||||||
|
|
||||||
|
- 如果是修复 bug,请在 PR 中给出描述信息。
|
||||||
|
|
||||||
|
- 如果PR是新功能,确保完成相关文档(/lancet/docs/api/packages)。
|
||||||
1135
README_zh-CN.md
1135
README_zh-CN.md
File diff suppressed because it is too large
Load Diff
@@ -99,7 +99,7 @@ func (c *cloner) cloneArray(v reflect.Value) reflect.Value {
|
|||||||
for i := 0; i < v.Len(); i++ {
|
for i := 0; i < v.Len(); i++ {
|
||||||
val := c.clone(v.Index(i))
|
val := c.clone(v.Index(i))
|
||||||
|
|
||||||
if val.IsValid() {
|
if !val.IsValid() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ func TestDeepClone(t *testing.T) {
|
|||||||
Nil: nil,
|
Nil: nil,
|
||||||
// unexported: "can't be cloned",
|
// unexported: "can't be cloned",
|
||||||
},
|
},
|
||||||
|
[]interface{}{1, &Struct{Str: "test"}, Struct{Str: "test2"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, item := range cases {
|
for i, item := range cases {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"crypto/des"
|
"crypto/des"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
"crypto/sha256"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io"
|
"io"
|
||||||
@@ -505,3 +506,32 @@ func RsaDecrypt(data []byte, privateKeyFileName string) []byte {
|
|||||||
}
|
}
|
||||||
return plainText
|
return plainText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateRsaKeyPair create rsa private and public key.
|
||||||
|
// Play: todo
|
||||||
|
func GenerateRsaKeyPair(keySize int) (*rsa.PrivateKey, *rsa.PublicKey) {
|
||||||
|
privateKey, _ := rsa.GenerateKey(rand.Reader, keySize)
|
||||||
|
return privateKey, &privateKey.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// RsaEncryptOAEP encrypts the given data with RSA-OAEP.
|
||||||
|
// Play: todo
|
||||||
|
func RsaEncryptOAEP(data []byte, label []byte, key rsa.PublicKey) ([]byte, error) {
|
||||||
|
encryptedBytes, err := rsa.EncryptOAEP(sha256.New(), rand.Reader, &key, data, label)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return encryptedBytes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RsaDecryptOAEP decrypts the data with RSA-OAEP.
|
||||||
|
// Play: todo
|
||||||
|
func RsaDecryptOAEP(ciphertext []byte, label []byte, key rsa.PrivateKey) ([]byte, error) {
|
||||||
|
decryptedBytes, err := rsa.DecryptOAEP(sha256.New(), rand.Reader, &key, ciphertext, label)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return decryptedBytes, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package cryptor
|
package cryptor
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
func ExampleAesEcbEncrypt() {
|
func ExampleAesEcbEncrypt() {
|
||||||
data := "hello"
|
data := "hello"
|
||||||
@@ -484,3 +486,25 @@ func ExampleSha512WithBase64() {
|
|||||||
// Output:
|
// Output:
|
||||||
// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==
|
// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleRsaEncryptOAEP() {
|
||||||
|
pri, pub := GenerateRsaKeyPair(1024)
|
||||||
|
|
||||||
|
data := []byte("hello world")
|
||||||
|
label := []byte("123456")
|
||||||
|
|
||||||
|
encrypted, err := RsaEncryptOAEP(data, label, *pub)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypted, err := RsaDecryptOAEP([]byte(encrypted), label, *pri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(decrypted))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// hello world
|
||||||
|
}
|
||||||
|
|||||||
@@ -150,3 +150,21 @@ func TestRsaEncrypt(t *testing.T) {
|
|||||||
assert := internal.NewAssert(t, "TestRsaEncrypt")
|
assert := internal.NewAssert(t, "TestRsaEncrypt")
|
||||||
assert.Equal(string(data), string(decrypted))
|
assert.Equal(string(data), string(decrypted))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRsaEncryptOAEP(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestRsaEncrypt")
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
pri, pub := GenerateRsaKeyPair(1024)
|
||||||
|
|
||||||
|
data := []byte("hello world")
|
||||||
|
label := []byte("123456")
|
||||||
|
|
||||||
|
encrypted, err := RsaEncryptOAEP(data, label, *pub)
|
||||||
|
assert.IsNil(err)
|
||||||
|
|
||||||
|
decrypted, err := RsaDecryptOAEP([]byte(encrypted), label, *pri)
|
||||||
|
|
||||||
|
assert.IsNil(err)
|
||||||
|
assert.Equal("hello world", string(decrypted))
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
// ArrayQueue implements queue with slice
|
// ArrayQueue implements queue with slice
|
||||||
type ArrayQueue[T any] struct {
|
type ArrayQueue[T any] struct {
|
||||||
items []T
|
data []T
|
||||||
head int
|
head int
|
||||||
tail int
|
tail int
|
||||||
capacity int
|
capacity int
|
||||||
@@ -21,7 +21,7 @@ type ArrayQueue[T any] struct {
|
|||||||
|
|
||||||
func NewArrayQueue[T any](capacity int) *ArrayQueue[T] {
|
func NewArrayQueue[T any](capacity int) *ArrayQueue[T] {
|
||||||
return &ArrayQueue[T]{
|
return &ArrayQueue[T]{
|
||||||
items: make([]T, 0, capacity),
|
data: make([]T, 0, capacity),
|
||||||
head: 0,
|
head: 0,
|
||||||
tail: 0,
|
tail: 0,
|
||||||
capacity: capacity,
|
capacity: capacity,
|
||||||
@@ -33,7 +33,7 @@ func NewArrayQueue[T any](capacity int) *ArrayQueue[T] {
|
|||||||
func (q *ArrayQueue[T]) Data() []T {
|
func (q *ArrayQueue[T]) Data() []T {
|
||||||
items := []T{}
|
items := []T{}
|
||||||
for i := q.head; i < q.tail; i++ {
|
for i := q.head; i < q.tail; i++ {
|
||||||
items = append(items, q.items[i])
|
items = append(items, q.data[i])
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
@@ -55,40 +55,71 @@ func (q *ArrayQueue[T]) IsFull() bool {
|
|||||||
|
|
||||||
// Front return front value of queue
|
// Front return front value of queue
|
||||||
func (q *ArrayQueue[T]) Front() T {
|
func (q *ArrayQueue[T]) Front() T {
|
||||||
return q.items[0]
|
return q.data[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Back return back value of queue
|
// Back return back value of queue
|
||||||
func (q *ArrayQueue[T]) Back() T {
|
func (q *ArrayQueue[T]) Back() T {
|
||||||
return q.items[q.size-1]
|
return q.data[q.size-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnQueue put element into queue
|
// EnQueue put element into queue
|
||||||
func (q *ArrayQueue[T]) Enqueue(item T) bool {
|
func (q *ArrayQueue[T]) Enqueue(item T) bool {
|
||||||
if q.head == 0 && q.tail == q.capacity {
|
if q.tail < q.capacity {
|
||||||
return false
|
q.data = append(q.data, item)
|
||||||
} else if q.head != 0 && q.tail == q.capacity {
|
// q.tail++
|
||||||
for i := q.head; i < q.tail; i++ {
|
q.data[q.tail] = item
|
||||||
q.items[i-q.head] = q.items[i]
|
} else {
|
||||||
|
//upgrade
|
||||||
|
if q.head > 0 {
|
||||||
|
for i := 0; i < q.tail-q.head; i++ {
|
||||||
|
q.data[i] = q.data[i+q.head]
|
||||||
|
}
|
||||||
|
q.tail -= q.head
|
||||||
|
q.head = 0
|
||||||
|
} else {
|
||||||
|
if q.capacity < 65536 {
|
||||||
|
if q.capacity == 0 {
|
||||||
|
q.capacity = 1
|
||||||
|
}
|
||||||
|
q.capacity *= 2
|
||||||
|
} else {
|
||||||
|
q.capacity += 2 ^ 16
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp := make([]T, q.capacity, q.capacity)
|
||||||
|
copy(tmp, q.data)
|
||||||
|
q.data = tmp
|
||||||
}
|
}
|
||||||
q.tail = q.tail - q.head
|
|
||||||
q.head = 0
|
q.data[q.tail] = item
|
||||||
}
|
}
|
||||||
|
|
||||||
q.items = append(q.items, item)
|
|
||||||
q.tail++
|
q.tail++
|
||||||
q.size++
|
q.size++
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeQueue remove head element of queue and return it, if queue is empty, return nil and error
|
// DeQueue remove head element of queue and return it, if queue is empty, return nil and error
|
||||||
func (q *ArrayQueue[T]) Dequeue() (T, bool) {
|
func (q *ArrayQueue[T]) Dequeue() (T, bool) {
|
||||||
var item T
|
var item T
|
||||||
if q.head == q.tail {
|
if q.size == 0 {
|
||||||
return item, false
|
return item, false
|
||||||
}
|
}
|
||||||
item = q.items[q.head]
|
|
||||||
|
item = q.data[q.head]
|
||||||
q.head++
|
q.head++
|
||||||
|
|
||||||
|
if q.head >= 1024 || q.head*2 > q.tail {
|
||||||
|
q.capacity -= q.head
|
||||||
|
q.tail -= q.head
|
||||||
|
tmp := make([]T, q.capacity, q.capacity)
|
||||||
|
copy(tmp, q.data[q.head:])
|
||||||
|
q.data = tmp
|
||||||
|
q.head = 0
|
||||||
|
}
|
||||||
|
|
||||||
q.size--
|
q.size--
|
||||||
return item, true
|
return item, true
|
||||||
}
|
}
|
||||||
@@ -96,7 +127,7 @@ func (q *ArrayQueue[T]) Dequeue() (T, bool) {
|
|||||||
// Clear the queue data
|
// Clear the queue data
|
||||||
func (q *ArrayQueue[T]) Clear() {
|
func (q *ArrayQueue[T]) Clear() {
|
||||||
capacity := q.capacity
|
capacity := q.capacity
|
||||||
q.items = make([]T, 0, capacity)
|
q.data = make([]T, 0, capacity)
|
||||||
q.head = 0
|
q.head = 0
|
||||||
q.tail = 0
|
q.tail = 0
|
||||||
q.size = 0
|
q.size = 0
|
||||||
@@ -105,7 +136,7 @@ func (q *ArrayQueue[T]) Clear() {
|
|||||||
|
|
||||||
// Contain checks if the value is in queue or not
|
// Contain checks if the value is in queue or not
|
||||||
func (q *ArrayQueue[T]) Contain(value T) bool {
|
func (q *ArrayQueue[T]) Contain(value T) bool {
|
||||||
for _, v := range q.items {
|
for _, v := range q.data {
|
||||||
if reflect.DeepEqual(v, value) {
|
if reflect.DeepEqual(v, value) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -117,7 +148,7 @@ func (q *ArrayQueue[T]) Contain(value T) bool {
|
|||||||
func (q *ArrayQueue[T]) Print() {
|
func (q *ArrayQueue[T]) Print() {
|
||||||
info := "["
|
info := "["
|
||||||
for i := q.head; i < q.tail; i++ {
|
for i := q.head; i < q.tail; i++ {
|
||||||
info += fmt.Sprintf("%+v, ", q.items[i])
|
info += fmt.Sprintf("%+v, ", q.data[i])
|
||||||
}
|
}
|
||||||
info += "]"
|
info += "]"
|
||||||
fmt.Println(info)
|
fmt.Println(info)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ func TestArrayQueue_Enqueue(t *testing.T) {
|
|||||||
|
|
||||||
assert := internal.NewAssert(t, "TestArrayQueue_Enqueue")
|
assert := internal.NewAssert(t, "TestArrayQueue_Enqueue")
|
||||||
|
|
||||||
queue := NewArrayQueue[int](5)
|
queue := NewArrayQueue[int](2)
|
||||||
queue.Enqueue(1)
|
queue.Enqueue(1)
|
||||||
queue.Enqueue(2)
|
queue.Enqueue(2)
|
||||||
queue.Enqueue(3)
|
queue.Enqueue(3)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const slugify = (str: string): string =>
|
|||||||
|
|
||||||
export const commonConfig = defineConfig({
|
export const commonConfig = defineConfig({
|
||||||
title: 'Lancet',
|
title: 'Lancet',
|
||||||
appearance: 'dark',
|
appearance: true,
|
||||||
|
|
||||||
markdown: {
|
markdown: {
|
||||||
theme: {
|
theme: {
|
||||||
@@ -83,7 +83,7 @@ export const commonConfig = defineConfig({
|
|||||||
|
|
||||||
footer: {
|
footer: {
|
||||||
copyright: 'Copyright © 2023-present Duke Du',
|
copyright: 'Copyright © 2023-present Duke Du',
|
||||||
message: 'Released under the MIT License.',
|
message: '备案号: 京ICP备2023022770号',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { DefaultTheme, LocaleSpecificConfig } from 'vitepress'
|
import type { DefaultTheme, LocaleSpecificConfig } from 'vitepress'
|
||||||
|
|
||||||
export const META_URL = 'https://golancet.dev'
|
export const META_URL = 'https://www.golancet.cn/en/'
|
||||||
export const META_TITLE = 'Lancet'
|
export const META_TITLE = 'Lancet'
|
||||||
export const META_DESCRIPTION = 'A powerful util function library of Go'
|
export const META_DESCRIPTION = 'A powerful util function library of Go'
|
||||||
|
|
||||||
@@ -10,12 +10,13 @@ export const enConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
head: [
|
head: [
|
||||||
['meta', { property: 'og:url', content: META_URL }],
|
['meta', { property: 'og:url', content: META_URL }],
|
||||||
['meta', { property: 'og:description', content: META_DESCRIPTION }],
|
['meta', { property: 'og:description', content: META_DESCRIPTION }],
|
||||||
['meta', { property: 'twitter:url', content: META_URL }],
|
|
||||||
['meta', { property: 'twitter:title', content: META_TITLE }],
|
|
||||||
['meta', { property: 'twitter:description', content: META_DESCRIPTION }],
|
|
||||||
],
|
],
|
||||||
|
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
|
editLink: {
|
||||||
|
pattern: 'https://github.com/duke-git/lancet/edit/v2/docs/:path',
|
||||||
|
text: 'Suggest changes to this page',
|
||||||
|
},
|
||||||
nav: [
|
nav: [
|
||||||
{
|
{
|
||||||
text: 'Home',
|
text: 'Home',
|
||||||
@@ -32,15 +33,23 @@ export const enConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
text: 'Links',
|
text: 'Links',
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
text: 'Releaselog',
|
text: 'Discussion',
|
||||||
|
link: 'https://github.com/duke-git/lancet/discussions',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Changelog',
|
||||||
link: 'https://github.com/duke-git/lancet/releases',
|
link: 'https://github.com/duke-git/lancet/releases',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: 'Contribution',
|
||||||
|
link: 'https://github.com/duke-git/lancet/blob/main/CONTRIBUTING.en-US.md',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
sidebar: {
|
sidebar: {
|
||||||
'/en/': [
|
'/en/guide/': [
|
||||||
{
|
{
|
||||||
text: 'Introduction',
|
text: 'Introduction',
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
@@ -50,19 +59,37 @@ export const enConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
link: '/en/guide/introduction',
|
link: '/en/guide/introduction',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'getting started',
|
text: 'Getting started',
|
||||||
link: '/en/guide/getting_started',
|
link: '/en/guide/getting_started',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: 'Contribute Code',
|
||||||
|
collapsed: false,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: 'Contribution guide',
|
||||||
|
link: '/en/guide/contribution_guide',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Contributors',
|
||||||
|
link: '/en/guide/contributors',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'API Reference',
|
||||||
|
link: '/en/api/overview'
|
||||||
|
},
|
||||||
],
|
],
|
||||||
'/en/api/': [
|
'/en/api/': [
|
||||||
{
|
{
|
||||||
text: 'overview',
|
text: 'Overview',
|
||||||
items: [{ text: 'overview of API', link: '/en/api/overview' }],
|
items: [{ text: 'API overview', link: '/en/api/overview' }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'packages',
|
text: 'Packages',
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
items: [
|
items: [
|
||||||
{ text: 'algorithm', link: '/en/api/packages/algorithm' },
|
{ text: 'algorithm', link: '/en/api/packages/algorithm' },
|
||||||
@@ -94,6 +121,16 @@ export const enConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
{ text: 'maputil', link: '/en/api/packages/maputil' },
|
{ text: 'maputil', link: '/en/api/packages/maputil' },
|
||||||
{ text: 'netutil', link: '/en/api/packages/netutil' },
|
{ text: 'netutil', link: '/en/api/packages/netutil' },
|
||||||
{ text: 'pointer', link: '/en/api/packages/pointer' },
|
{ text: 'pointer', link: '/en/api/packages/pointer' },
|
||||||
|
{ text: 'random', link: '/en/api/packages/random' },
|
||||||
|
{ text: 'retry', link: '/en/api/packages/retry' },
|
||||||
|
{ text: 'slice', link: '/en/api/packages/slice' },
|
||||||
|
{ text: 'stream', link: '/en/api/packages/stream' },
|
||||||
|
{ text: 'struct', link: '/en/api/packages/struct' },
|
||||||
|
{ text: 'strutil', link: '/en/api/packages/strutil' },
|
||||||
|
{ text: 'system', link: '/en/api/packages/system' },
|
||||||
|
{ text: 'tuple', link: '/en/api/packages/tuple' },
|
||||||
|
{ text: 'validator', link: '/en/api/packages/validator' },
|
||||||
|
{ text: 'xerror', link: '/en/api/packages/xerror' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { DefaultTheme, LocaleSpecificConfig } from 'vitepress'
|
import type { DefaultTheme, LocaleSpecificConfig } from 'vitepress'
|
||||||
|
|
||||||
export const META_URL = 'https://lancet.dev'
|
export const META_URL = 'https://www.golancet.cn'
|
||||||
export const META_TITLE = 'Lancet'
|
export const META_TITLE = 'Lancet'
|
||||||
export const META_DESCRIPTION = '一个强大的Go语言工具函数库'
|
export const META_DESCRIPTION = '一个强大的Go语言工具函数库'
|
||||||
|
|
||||||
@@ -10,12 +10,13 @@ export const zhConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
head: [
|
head: [
|
||||||
['meta', { property: 'og:url', content: META_URL }],
|
['meta', { property: 'og:url', content: META_URL }],
|
||||||
['meta', { property: 'og:description', content: META_DESCRIPTION }],
|
['meta', { property: 'og:description', content: META_DESCRIPTION }],
|
||||||
['meta', { property: 'twitter:url', content: META_URL }],
|
|
||||||
['meta', { property: 'twitter:title', content: META_TITLE }],
|
|
||||||
['meta', { property: 'twitter:description', content: META_DESCRIPTION }],
|
|
||||||
],
|
],
|
||||||
|
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
|
editLink: {
|
||||||
|
pattern: 'https://github.com/duke-git/lancet/edit/v2/docs/:path',
|
||||||
|
text: '对本页提出修改建议',
|
||||||
|
},
|
||||||
outline: {
|
outline: {
|
||||||
label: '本页内容',
|
label: '本页内容',
|
||||||
},
|
},
|
||||||
@@ -40,19 +41,27 @@ export const zhConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
{
|
{
|
||||||
text: '相关链接',
|
text: '相关链接',
|
||||||
items: [
|
items: [
|
||||||
|
{
|
||||||
|
text: '论坛',
|
||||||
|
link: 'https://github.com/duke-git/lancet/discussions',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: '更新日志',
|
text: '更新日志',
|
||||||
link: 'https://github.com/duke-git/lancet/releases',
|
link: 'https://github.com/duke-git/lancet/releases',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: '参与贡献',
|
||||||
|
link: 'https://github.com/duke-git/lancet/blob/main/CONTRIBUTING.zh-CN.md',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
sidebar: {
|
sidebar: {
|
||||||
'/': [
|
'/guide/': [
|
||||||
{
|
{
|
||||||
text: '介绍',
|
text: '介绍',
|
||||||
collapsed: true,
|
collapsed: false,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
text: 'Lancet是什么?',
|
text: 'Lancet是什么?',
|
||||||
@@ -64,6 +73,24 @@ export const zhConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: '贡献代码',
|
||||||
|
collapsed: false,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
text: '贡献指南',
|
||||||
|
link: '/guide/contribution_guide',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: '贡献者',
|
||||||
|
link: '/guide/contributors',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'API手册',
|
||||||
|
link: '/api/overview'
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
'/api/': [
|
'/api/': [
|
||||||
@@ -107,6 +134,16 @@ export const zhConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
|
|||||||
{ text: 'Map', link: '/api/packages/maputil' },
|
{ text: 'Map', link: '/api/packages/maputil' },
|
||||||
{ text: '网络', link: '/api/packages/netutil' },
|
{ text: '网络', link: '/api/packages/netutil' },
|
||||||
{ text: '指针', link: '/api/packages/pointer' },
|
{ text: '指针', link: '/api/packages/pointer' },
|
||||||
|
{ text: '随机数', link: '/api/packages/random' },
|
||||||
|
{ text: '重试', link: '/api/packages/retry' },
|
||||||
|
{ text: '切片', link: '/api/packages/slice' },
|
||||||
|
{ text: '流', link: '/api/packages/stream' },
|
||||||
|
{ text: '结构体', link: '/api/packages/struct' },
|
||||||
|
{ text: '字符串', link: '/api/packages/strutil' },
|
||||||
|
{ text: '系统', link: '/api/packages/system' },
|
||||||
|
{ text: '元组', link: '/api/packages/tuple' },
|
||||||
|
{ text: '验证器', link: '/api/packages/validator' },
|
||||||
|
{ text: '错误处理', link: '/api/packages/xerror' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ outline: deep
|
|||||||
|
|
||||||
# API概述
|
# API概述
|
||||||
|
|
||||||
<b>lancet(柳叶刀)是一个强大、全面、高效、可复用的go语言工具函数库。包含25个包,超过600个工具函数。功能涵盖字符串处理、切片处理、网络、并发、加解密、文件处理、时间/日期、流处理、迭代器等等。</b>
|
<b>lancet(柳叶刀)是一个功能强大、全面、高效、可复用的go语言工具函数库。包含25个包,超过600个工具函数。功能涵盖字符串处理、切片处理、网络、并发、加解密、文件处理、时间/日期、流处理、迭代器等等。</b>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -27,7 +27,7 @@ outline: deep
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
background: #ecefff;
|
background: #10b981;
|
||||||
border: 1px solid;
|
border: 1px solid;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="BubbleSort">BubbleSort</span>
|
### <span id="BubbleSort">BubbleSort</span>
|
||||||
@@ -53,7 +51,7 @@ import (
|
|||||||
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/GNdv7Jg2Taj)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/GNdv7Jg2Taj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -101,7 +99,7 @@ func main() {
|
|||||||
func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/G5LJiWgJJW6)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/G5LJiWgJJW6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -164,7 +162,7 @@ func main() {
|
|||||||
func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/oXovbkekayS)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/oXovbkekayS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -212,7 +210,7 @@ func main() {
|
|||||||
func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/3ibkszpJEu3)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/3ibkszpJEu3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -260,7 +258,7 @@ func main() {
|
|||||||
func QuickSort[T any](slice []T comparator lancetconstraints.Comparator)
|
func QuickSort[T any](slice []T comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/7Y7c1Elk3ax)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/7Y7c1Elk3ax)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -308,7 +306,7 @@ func main() {
|
|||||||
func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/u6Iwa1VZS_f)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/u6Iwa1VZS_f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -356,7 +354,7 @@ func main() {
|
|||||||
func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ydinn9YzUJn)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ydinn9YzUJn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -404,7 +402,7 @@ func main() {
|
|||||||
func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
|
func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tB-Umgm0DrP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tB-Umgm0DrP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -453,7 +451,7 @@ func main() {
|
|||||||
func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/t6MeGiUSN47)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/t6MeGiUSN47)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -504,7 +502,7 @@ func main() {
|
|||||||
func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/Anozfr8ZLH3)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Anozfr8ZLH3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -555,7 +553,7 @@ func main() {
|
|||||||
func LinearSearch[T any](slice []T, target T, equal func(a, b T) bool) int
|
func LinearSearch[T any](slice []T, target T, equal func(a, b T) bool) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/IsS7rgn5s3x)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/IsS7rgn5s3x)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -598,7 +596,7 @@ func (l *LRUCache[K, V]) Delete(key K) bool
|
|||||||
func (l *LRUCache[K, V]) Len() int
|
func (l *LRUCache[K, V]) Len() int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/-EZjgOURufP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/-EZjgOURufP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="Equal">Equal</span>
|
### <span id="Equal">Equal</span>
|
||||||
@@ -49,7 +47,7 @@ import (
|
|||||||
func Equal(left, right any) bool
|
func Equal(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/wmVxR-to4lz)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/wmVxR-to4lz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -98,7 +96,7 @@ func main() {
|
|||||||
func EqualValue(left, right any) bool
|
func EqualValue(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/fxnna_LLD9u)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fxnna_LLD9u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -137,7 +135,7 @@ func main() {
|
|||||||
func LessThan(left, right any) bool
|
func LessThan(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/cYh7FQQj0ne)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/cYh7FQQj0ne)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -186,7 +184,7 @@ func main() {
|
|||||||
func GreaterThan(left, right any) bool
|
func GreaterThan(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/9-NYDFZmIMp)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9-NYDFZmIMp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -238,7 +236,7 @@ func main() {
|
|||||||
func LessOrEqual(left, right any) bool
|
func LessOrEqual(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/e4T_scwoQzp)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/e4T_scwoQzp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -287,7 +285,7 @@ func main() {
|
|||||||
func GreaterOrEqual(left, right any) bool
|
func GreaterOrEqual(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/vx8mP0U8DFk)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/vx8mP0U8DFk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -339,7 +337,7 @@ func main() {
|
|||||||
func InDelta[T constraints.Integer | constraints.Float](left, right T, delta float64) bool
|
func InDelta[T constraints.Integer | constraints.Float](left, right T, delta float64) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例: <span class="run-container">[运行](https://go.dev/play/p/TuDdcNtMkjo)</span></b>
|
<b>示例: <span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/TuDdcNtMkjo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
# Concurrency
|
# Concurrency
|
||||||
并发包包含一些支持并发编程的功能。例如:goroutine, channel等。
|
|
||||||
|
并发包包含一些支持并发编程的功能。例如:goroutine, channel 等。
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 源码:
|
## 源码:
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/concurrency/channel.go](https://github.com/duke-git/lancet/blob/main/concurrency/channel.go)
|
- [https://github.com/duke-git/lancet/blob/main/concurrency/channel.go](https://github.com/duke-git/lancet/blob/main/concurrency/channel.go)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 用法:
|
## 用法:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"github.com/duke-git/lancet/v2/concurrency"
|
"github.com/duke-git/lancet/v2/concurrency"
|
||||||
@@ -19,25 +21,24 @@ import (
|
|||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
|
|
||||||
### Channel
|
### Channel
|
||||||
- [NewChannel](#NewChannel)
|
|
||||||
- [Bridge](#Bridge)
|
- [NewChannel](#NewChannel)
|
||||||
- [FanIn](#FanIn)
|
- [Bridge](#Bridge)
|
||||||
- [Generate](#Generate)
|
- [FanIn](#FanIn)
|
||||||
- [Or](#Or)
|
- [Generate](#Generate)
|
||||||
- [OrDone](#OrDone)
|
- [Or](#Or)
|
||||||
- [Repeat](#Repeat)
|
- [OrDone](#OrDone)
|
||||||
- [RepeatFn](#RepeatFn)
|
- [Repeat](#Repeat)
|
||||||
- [Take](#Take)
|
- [RepeatFn](#RepeatFn)
|
||||||
- [Tee](#Tee)
|
- [Take](#Take)
|
||||||
|
- [Tee](#Tee)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
|
|
||||||
### Channel
|
### Channel
|
||||||
|
|
||||||
### <span id="NewChannel">NewChannel</span>
|
### <span id="NewChannel">NewChannel</span>
|
||||||
@@ -50,7 +51,8 @@ import (
|
|||||||
type Channel[T any] struct
|
type Channel[T any] struct
|
||||||
func NewChannel[T any]() *Channel[T]
|
func NewChannel[T any]() *Channel[T]
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -74,7 +76,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Bridge(ctx context.Context, chanStream <-chan <-chan T) <-chan T
|
func (c *Channel[T]) Bridge(ctx context.Context, chanStream <-chan <-chan T) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/qmWSy1NVF-Y)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qmWSy1NVF-Y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -126,7 +129,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) FanIn(ctx context.Context, channels ...<-chan T) <-chan T
|
func (c *Channel[T]) FanIn(ctx context.Context, channels ...<-chan T) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/2VYFMexEvTm)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/2VYFMexEvTm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -165,7 +169,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Generate(ctx context.Context, values ...T) <-chan T
|
func (c *Channel[T]) Generate(ctx context.Context, values ...T) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -203,7 +208,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Repeat(ctx context.Context, values ...T) <-chan T
|
func (c *Channel[T]) Repeat(ctx context.Context, values ...T) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/k5N_ALVmYjE)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/k5N_ALVmYjE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -242,7 +248,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) RepeatFn(ctx context.Context, fn func() T) <-chan T
|
func (c *Channel[T]) RepeatFn(ctx context.Context, fn func() T) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4J1zAWttP85)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4J1zAWttP85)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -283,7 +290,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Or(channels ...<-chan T) <-chan T
|
func (c *Channel[T]) Or(channels ...<-chan T) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Wqz9rwioPww)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Wqz9rwioPww)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -326,7 +334,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) OrDone(ctx context.Context, channel <-chan T) <-chan T
|
func (c *Channel[T]) OrDone(ctx context.Context, channel <-chan T) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/lm_GoS6aDjo)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/lm_GoS6aDjo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -364,7 +373,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Take(ctx context.Context, valueStream <-chan T, number int) <-chan T
|
func (c *Channel[T]) Take(ctx context.Context, valueStream <-chan T, number int) <-chan T
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/9Utt-1pDr2J)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9Utt-1pDr2J)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -410,7 +420,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Tee(ctx context.Context, in <-chan T) (<-chan T, <-chan T)
|
func (c *Channel[T]) Tee(ctx context.Context, in <-chan T) (<-chan T, <-chan T)
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/3TQPKnCirrP)</span></b>
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/3TQPKnCirrP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -440,4 +451,4 @@ func main() {
|
|||||||
// 1
|
// 1
|
||||||
// 1
|
// 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="Bool">Bool</span>
|
### <span id="Bool">Bool</span>
|
||||||
@@ -47,7 +45,7 @@ slices和map的length大于0时,返回true,否则返回false<br/>
|
|||||||
```go
|
```go
|
||||||
func Bool[T any](value T) bool
|
func Bool[T any](value T) bool
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ETzeDJRSvhm)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ETzeDJRSvhm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -111,7 +109,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func And[T, U any](a T, b U) bool
|
func And[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/W1SSUmt6pvr)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/W1SSUmt6pvr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -137,7 +135,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Or[T, U any](a T, b U) bool
|
func Or[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/UlQTxHaeEkq)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/UlQTxHaeEkq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -163,7 +161,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Xor[T, U any](a T, b U) bool
|
func Xor[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/gObZrW7ZbG8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/gObZrW7ZbG8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -189,7 +187,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Nor[T, U any](a T, b U) bool
|
func Nor[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/g2j08F_zZky)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/g2j08F_zZky)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -215,7 +213,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Xnor[T, U any](a T, b U) bool
|
func Xnor[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/OuDB9g51643)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/OuDB9g51643)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -241,7 +239,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Nand[T, U any](a T, b U) bool
|
func Nand[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/vSRMLxLIbq8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/vSRMLxLIbq8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -267,7 +265,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U
|
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U
|
||||||
```
|
```
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ElllPZY0guT)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ElllPZY0guT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="ColorHexToRGB">ColorHexToRGB</span>
|
### <span id="ColorHexToRGB">ColorHexToRGB</span>
|
||||||
@@ -60,7 +58,7 @@ import (
|
|||||||
func ColorHexToRGB(colorHex string) (red, green, blue int)
|
func ColorHexToRGB(colorHex string) (red, green, blue int)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/o7_ft-JCJBV)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/o7_ft-JCJBV)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -91,7 +89,7 @@ func main() {
|
|||||||
func ColorRGBToHex(red, green, blue int) string
|
func ColorRGBToHex(red, green, blue int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nzKS2Ro87J1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nzKS2Ro87J1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -124,7 +122,7 @@ func main() {
|
|||||||
func ToBool(s string) (bool, error)
|
func ToBool(s string) (bool, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ARht2WnGdIN)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ARht2WnGdIN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -165,7 +163,7 @@ func main() {
|
|||||||
func ToBytes(data any) ([]byte, error)
|
func ToBytes(data any) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/fAMXYFDvOvr)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fAMXYFDvOvr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -198,7 +196,7 @@ func main() {
|
|||||||
func ToChar(s string) []string
|
func ToChar(s string) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/JJ1SvbFkVdM)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/JJ1SvbFkVdM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -234,7 +232,7 @@ func main() {
|
|||||||
func ToChannel[T any](array []T) <-chan T
|
func ToChannel[T any](array []T) <-chan T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/hOx_oYZbAnL)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/hOx_oYZbAnL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -271,7 +269,7 @@ func main() {
|
|||||||
func ToFloat(value any) (float64, error)
|
func ToFloat(value any) (float64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4YTmPCibqHJ)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4YTmPCibqHJ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -316,7 +314,7 @@ func main() {
|
|||||||
func ToInt(value any) (int64, error)
|
func ToInt(value any) (int64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/9_h9vIt-QZ_b)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9_h9vIt-QZ_b)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -358,7 +356,7 @@ func main() {
|
|||||||
func ToJson(value any) (string, error)
|
func ToJson(value any) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/2rLIkMmXWvR)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/2rLIkMmXWvR)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -393,7 +391,7 @@ func main() {
|
|||||||
func ToMap[T any, K comparable, V any](array []T, iteratee func(T) (K, V)) map[K]V
|
func ToMap[T any, K comparable, V any](array []T, iteratee func(T) (K, V)) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tVFy7E-t24l)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tVFy7E-t24l)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -434,7 +432,7 @@ func main() {
|
|||||||
func ToPointer[T any](value T) *T
|
func ToPointer[T any](value T) *T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ASf_etHNlw1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ASf_etHNlw1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -463,7 +461,7 @@ func main() {
|
|||||||
func ToString(value any) string
|
func ToString(value any) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nF1zOOslpQq)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nF1zOOslpQq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -511,7 +509,7 @@ func main() {
|
|||||||
func StructToMap(value any) (map[string]any, error)
|
func StructToMap(value any) (map[string]any, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/KYGYJqNUBOI)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KYGYJqNUBOI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -549,7 +547,7 @@ func main() {
|
|||||||
func MapToSlice[T any, K comparable, V any](aMap map[K]V, iteratee func(K, V) T) []T
|
func MapToSlice[T any, K comparable, V any](aMap map[K]V, iteratee func(K, V) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/dmX4Ix5V6Wl)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/dmX4Ix5V6Wl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -579,7 +577,7 @@ func main() {
|
|||||||
func EncodeByte(data any) ([]byte, error)
|
func EncodeByte(data any) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/DVmM1G5JfuP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/DVmM1G5JfuP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -608,7 +606,7 @@ func main() {
|
|||||||
func DecodeByte(data []byte, target any) error
|
func DecodeByte(data []byte, target any) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -644,7 +642,7 @@ func main() {
|
|||||||
func DeepClone[T any](src T) T
|
func DeepClone[T any](src T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/j4DP5dquxnk)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/j4DP5dquxnk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -708,7 +706,7 @@ func main() {
|
|||||||
func CopyProperties[T, U any](dst T, src U) (err error)
|
func CopyProperties[T, U any](dst T, src U) (err error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/oZujoB5Sgg5)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/oZujoB5Sgg5)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -787,7 +785,7 @@ func main() {
|
|||||||
func ToInterface(v reflect.Value) (value interface{}, ok bool)
|
func ToInterface(v reflect.Value) (value interface{}, ok bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/syqw0-WG7Xd)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/syqw0-WG7Xd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -822,7 +820,7 @@ func main() {
|
|||||||
func Utf8ToGbk(bs []byte) ([]byte, error)
|
func Utf8ToGbk(bs []byte) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/9FlIaFLArIL)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9FlIaFLArIL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -856,7 +854,7 @@ func main() {
|
|||||||
func GbkToUtf8(bs []byte) ([]byte, error)
|
func GbkToUtf8(bs []byte) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/OphmHCN_9u8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/OphmHCN_9u8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Cryptor
|
# Cryptor
|
||||||
|
|
||||||
cryptor包包含数据加密和解密功能。支持 base64, md5, hmac, hash, aes, des, rsa。
|
cryptor 包包含数据加密和解密功能。支持 base64, md5, hmac, hash, aes, des, rsa。
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -65,11 +65,12 @@ import (
|
|||||||
- [GenerateRsaKey](#GenerateRsaKey)
|
- [GenerateRsaKey](#GenerateRsaKey)
|
||||||
- [RsaEncrypt](#RsaEncrypt)
|
- [RsaEncrypt](#RsaEncrypt)
|
||||||
- [RsaDecrypt](#RsaDecrypt)
|
- [RsaDecrypt](#RsaDecrypt)
|
||||||
|
- [GenerateRsaKeyPair](#GenerateRsaKeyPair)
|
||||||
|
- [RsaEncryptOAEP](#RsaEncryptOAEP)
|
||||||
|
- [RsaDecryptOAEP](#RsaDecryptOAEP)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="AesEcbEncrypt">AesEcbEncrypt</span>
|
### <span id="AesEcbEncrypt">AesEcbEncrypt</span>
|
||||||
@@ -82,7 +83,7 @@ import (
|
|||||||
func AesEcbEncrypt(data, key []byte) []byte
|
func AesEcbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -116,7 +117,7 @@ func main() {
|
|||||||
func AesEcbDecrypt(encrypted, key []byte) []byte
|
func AesEcbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -150,7 +151,7 @@ func main() {
|
|||||||
func AesCbcEncrypt(data, key []byte) []byte
|
func AesCbcEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -184,7 +185,7 @@ func main() {
|
|||||||
func AesCbcDecrypt(encrypted, key []byte) []byte
|
func AesCbcDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -218,7 +219,7 @@ func main() {
|
|||||||
func AesCtrCrypt(data, key []byte) []byte
|
func AesCtrCrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/SpaZO0-5Nsp)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/SpaZO0-5Nsp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -252,7 +253,7 @@ func main() {
|
|||||||
func AesCfbEncrypt(data, key []byte) []byte
|
func AesCfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -286,7 +287,7 @@ func main() {
|
|||||||
func AesCfbDecrypt(encrypted, key []byte) []byte
|
func AesCfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -320,7 +321,7 @@ func main() {
|
|||||||
func AesOfbEncrypt(data, key []byte) []byte
|
func AesOfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -354,7 +355,7 @@ func main() {
|
|||||||
func AesOfbDecrypt(encrypted, key []byte) []byte
|
func AesOfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -388,7 +389,7 @@ func main() {
|
|||||||
func Base64StdEncode(s string) string
|
func Base64StdEncode(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/VOaUyQUreoK)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/VOaUyQUreoK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -417,7 +418,7 @@ func main() {
|
|||||||
func Base64StdDecode(s string) string
|
func Base64StdDecode(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/RWQylnJVgIe)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/RWQylnJVgIe)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -446,7 +447,7 @@ func main() {
|
|||||||
func DesEcbEncrypt(data, key []byte) []byte
|
func DesEcbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -481,7 +482,7 @@ func main() {
|
|||||||
func DesEcbDecrypt(encrypted, key []byte) []byte
|
func DesEcbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -516,7 +517,7 @@ func main() {
|
|||||||
func DesCbcEncrypt(data, key []byte) []byte
|
func DesCbcEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -550,7 +551,7 @@ func main() {
|
|||||||
func DesCbcDecrypt(encrypted, key []byte) []byte
|
func DesCbcDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -584,7 +585,7 @@ func main() {
|
|||||||
func DesCtrCrypt(data, key []byte) []byte
|
func DesCtrCrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/9-T6OjKpcdw)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9-T6OjKpcdw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -618,7 +619,7 @@ func main() {
|
|||||||
func DesCfbEncrypt(data, key []byte) []byte
|
func DesCfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -652,7 +653,7 @@ func main() {
|
|||||||
func DesCfbDecrypt(encrypted, key []byte) []byte
|
func DesCfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -686,7 +687,7 @@ func main() {
|
|||||||
func DesOfbEncrypt(data, key []byte) []byte
|
func DesOfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -720,7 +721,7 @@ func main() {
|
|||||||
func DesOfbDecrypt(encrypted, key []byte) []byte
|
func DesOfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -754,7 +755,7 @@ func main() {
|
|||||||
func HmacMd5(str, key string) string
|
func HmacMd5(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -786,7 +787,7 @@ func main() {
|
|||||||
func HmacMd5WithBase64(str, key string) string
|
func HmacMd5WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/UY0ng2AefFC)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/UY0ng2AefFC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -818,7 +819,7 @@ func main() {
|
|||||||
func HmacSha1(str, key string) string
|
func HmacSha1(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/1UI4oQ4WXKM)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/1UI4oQ4WXKM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -850,7 +851,7 @@ func main() {
|
|||||||
func HmacSha1WithBase64(str, key string) string
|
func HmacSha1WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/47JmmGrnF7B)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/47JmmGrnF7B)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -882,7 +883,7 @@ func main() {
|
|||||||
func HmacSha256(str, key string) string
|
func HmacSha256(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/HhpwXxFhhC0)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HhpwXxFhhC0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -914,7 +915,7 @@ func main() {
|
|||||||
func HmacSha256WithBase64(str, key string) string
|
func HmacSha256WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/EKbkUvPTLwO)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/EKbkUvPTLwO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -946,7 +947,7 @@ func main() {
|
|||||||
func HmacSha512(str, key string) string
|
func HmacSha512(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/59Od6m4A0Ud)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/59Od6m4A0Ud)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -978,7 +979,7 @@ func main() {
|
|||||||
func HmacSha512WithBase64(str, key string) string
|
func HmacSha512WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/c6dSe3E2ydU)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/c6dSe3E2ydU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -990,13 +991,13 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
str := "hello"
|
str := "hello"
|
||||||
key := "12345"
|
key := "12345"
|
||||||
|
|
||||||
hms := cryptor.HmacSha512WithBase64(str, key)
|
hms := cryptor.HmacSha512WithBase64(str, key)
|
||||||
fmt.Println(hms)
|
fmt.Println(hms)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 3Y8SkKndI9NU4lJtmi6c6M///dN8syCADRxsE9Lvw2Mog3ahlsVFja9T+OGqa0Wm2FYwPVwKIGS/+XhYYdSM/A==
|
// 3Y8SkKndI9NU4lJtmi6c6M///dN8syCADRxsE9Lvw2Mog3ahlsVFja9T+OGqa0Wm2FYwPVwKIGS/+XhYYdSM/A==
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1010,7 +1011,7 @@ func main() {
|
|||||||
func Md5String(str string) string
|
func Md5String(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/1bLcVetbTOI)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/1bLcVetbTOI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1041,7 +1042,7 @@ func main() {
|
|||||||
func Md5StringWithBase64(s string) string
|
func Md5StringWithBase64(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Tcb-Z7LN2ax)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Tcb-Z7LN2ax)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1053,10 +1054,10 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
md5Str := cryptor.Md5StringWithBase64("hello")
|
md5Str := cryptor.Md5StringWithBase64("hello")
|
||||||
fmt.Println(md5Str)
|
fmt.Println(md5Str)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// XUFAKrxLKna5cZ2REBfFkg==
|
// XUFAKrxLKna5cZ2REBfFkg==
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1070,7 +1071,7 @@ func main() {
|
|||||||
func Md5Byte(data []byte) string
|
func Md5Byte(data []byte) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/suraalH8lyC)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/suraalH8lyC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1082,10 +1083,10 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
md5Str := cryptor.Md5Byte([]byte{'a'})
|
md5Str := cryptor.Md5Byte([]byte{'a'})
|
||||||
fmt.Println(md5Str)
|
fmt.Println(md5Str)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 0cc175b9c0f1b6a831c399e269772661
|
// 0cc175b9c0f1b6a831c399e269772661
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1099,7 +1100,7 @@ func main() {
|
|||||||
func Md5ByteWithBase64(data []byte) string
|
func Md5ByteWithBase64(data []byte) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Lx4gH7Vdr5_y)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Lx4gH7Vdr5_y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1111,10 +1112,10 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
md5Str := cryptor.Md5ByteWithBase64([]byte("hello"))
|
md5Str := cryptor.Md5ByteWithBase64([]byte("hello"))
|
||||||
fmt.Println(md5Str)
|
fmt.Println(md5Str)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// XUFAKrxLKna5cZ2REBfFkg==
|
// XUFAKrxLKna5cZ2REBfFkg==
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1154,7 +1155,7 @@ func main() {
|
|||||||
func Sha1(str string) string
|
func Sha1(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_m_uoD1deMT)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_m_uoD1deMT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1185,7 +1186,7 @@ func main() {
|
|||||||
func Sha1WithBase64(str string) string
|
func Sha1WithBase64(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/fSyx-Gl2l2-)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fSyx-Gl2l2-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1197,10 +1198,10 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result := cryptor.Sha1WithBase64("hello")
|
result := cryptor.Sha1WithBase64("hello")
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// qvTGHdzF6KLavt4PO0gs2a6pQ00=
|
// qvTGHdzF6KLavt4PO0gs2a6pQ00=
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1214,7 +1215,7 @@ func main() {
|
|||||||
func Sha256(str string) string
|
func Sha256(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tU9tfBMIAr1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tU9tfBMIAr1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1245,7 +1246,7 @@ func main() {
|
|||||||
func Sha256WithBase64(str string) string
|
func Sha256WithBase64(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/85IXJHIal1k)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/85IXJHIal1k)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1257,10 +1258,10 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result := cryptor.Sha256WithBase64("hello")
|
result := cryptor.Sha256WithBase64("hello")
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=
|
// LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1274,7 +1275,7 @@ func main() {
|
|||||||
func Sha512(str string) string
|
func Sha512(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/3WsvLYZxsHa)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/3WsvLYZxsHa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1305,7 +1306,7 @@ func main() {
|
|||||||
func Sha512WithBase64(str string) string
|
func Sha512WithBase64(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/q_fY2rA-k5I)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/q_fY2rA-k5I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1317,10 +1318,10 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result := cryptor.Sha512WithBase64("hello")
|
result := cryptor.Sha512WithBase64("hello")
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==
|
// m3HSJL1i83hdltRq0+o9czGb+8KJDKra4t/3JRlnPKcjI8PZm6XBHXx6zG4UuMXaDEZjR1wuXDre9G9zvN7AQw==
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1334,7 +1335,7 @@ func main() {
|
|||||||
func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error
|
func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/zutRHrDqs0X)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/zutRHrDqs0X)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1362,7 +1363,7 @@ func main() {
|
|||||||
func RsaEncrypt(data []byte, pubKeyFileName string) []byte
|
func RsaEncrypt(data []byte, pubKeyFileName string) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1399,7 +1400,7 @@ func main() {
|
|||||||
func RsaDecrypt(data []byte, privateKeyFileName string) []byte
|
func RsaDecrypt(data []byte, privateKeyFileName string) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1425,3 +1426,114 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="GenerateRsaKeyPair">GenerateRsaKeyPair</span>
|
||||||
|
|
||||||
|
<p>创建rsa公钥私钥和key。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func GenerateRsaKeyPair(keySize int) (*rsa.PrivateKey, *rsa.PublicKey)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/cryptor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pri, pub := cryptor.GenerateRsaKeyPair(1024)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="RsaEncryptOAEP">RsaEncryptOAEP</span>
|
||||||
|
|
||||||
|
<p>rsa OAEP加密。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func RsaEncryptOAEP(data []byte, label []byte, key rsa.PublicKey) ([]byte, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/cryptor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pri, pub := cryptor.GenerateRsaKeyPair(1024)
|
||||||
|
|
||||||
|
data := []byte("hello world")
|
||||||
|
label := []byte("123456")
|
||||||
|
|
||||||
|
encrypted, err := cryptor.RsaEncryptOAEP(data, label, *pub)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypted, err := cryptor.RsaDecryptOAEP([]byte(encrypted), label, *pri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(decrypted))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// hello world
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="RsaDecryptOAEP">RsaDecryptOAEP</span>
|
||||||
|
|
||||||
|
<p>rsa OAEP解密。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func RsaDecryptOAEP(ciphertext []byte, label []byte, key rsa.PrivateKey) ([]byte, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/cryptor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pri, pub := cryptor.GenerateRsaKeyPair(1024)
|
||||||
|
|
||||||
|
data := []byte("hello world")
|
||||||
|
label := []byte("123456")
|
||||||
|
|
||||||
|
encrypted, err := cryptor.RsaEncryptOAEP(data, label, *pub)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypted, err := cryptor.RsaDecryptOAEP([]byte(encrypted), label, *pri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(decrypted))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// hello world
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import (
|
|||||||
|
|
||||||
### <span id="NewHashMap">NewHashMap</span>
|
### <span id="NewHashMap">NewHashMap</span>
|
||||||
|
|
||||||
<p>新建默认容量(1 << 10)的HashMap指针实例</p>
|
<p>新建默认容量(1 << 10)的HashMap指针实例</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
## 注:
|
## 注:
|
||||||
@@ -108,7 +106,7 @@ import (
|
|||||||
func AddDay(t time.Time, day int64) time.Time
|
func AddDay(t time.Time, day int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/dIGbs_uTdFa)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/dIGbs_uTdFa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -147,7 +145,7 @@ func main() {
|
|||||||
func AddHour(t time.Time, hour int64) time.Time
|
func AddHour(t time.Time, hour int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/rcMjd7OCsi5)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/rcMjd7OCsi5)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -186,7 +184,7 @@ func main() {
|
|||||||
func AddMinute(t time.Time, minute int64) time.Time
|
func AddMinute(t time.Time, minute int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nT1heB1KUUK)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nT1heB1KUUK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -225,7 +223,7 @@ func main() {
|
|||||||
func AddYear(t time.Time, year int64) time.Time
|
func AddYear(t time.Time, year int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/MqW2ujnBx10)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/MqW2ujnBx10)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -264,7 +262,7 @@ func main() {
|
|||||||
func BeginOfMinute(t time.Time) time.Time
|
func BeginOfMinute(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ieOLVJ9CiFT)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ieOLVJ9CiFT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -296,7 +294,7 @@ func main() {
|
|||||||
func BeginOfHour(t time.Time) time.Time
|
func BeginOfHour(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/GhdGFnDWpYs)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/GhdGFnDWpYs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -328,7 +326,7 @@ func main() {
|
|||||||
func BeginOfDay(t time.Time) time.Time
|
func BeginOfDay(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/94m_UT6cWs9)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/94m_UT6cWs9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -360,7 +358,7 @@ func main() {
|
|||||||
func BeginOfWeek(t time.Time, beginFrom ...time.Weekday) time.Time
|
func BeginOfWeek(t time.Time, beginFrom ...time.Weekday) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ynjoJPz7VNV)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ynjoJPz7VNV)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -392,7 +390,7 @@ func main() {
|
|||||||
func BeginOfMonth(t time.Time) time.Time
|
func BeginOfMonth(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/bWXVFsmmzwL)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/bWXVFsmmzwL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -424,7 +422,7 @@ func main() {
|
|||||||
func BeginOfYear(t time.Time) time.Time
|
func BeginOfYear(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/i326DSwLnV8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/i326DSwLnV8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -456,7 +454,7 @@ func main() {
|
|||||||
func EndOfMinute(t time.Time) time.Time
|
func EndOfMinute(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/yrL5wGzPj4z)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/yrL5wGzPj4z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -488,7 +486,7 @@ func main() {
|
|||||||
func EndOfHour(t time.Time) time.Time
|
func EndOfHour(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/6ce3j_6cVqN)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/6ce3j_6cVqN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -520,7 +518,7 @@ func main() {
|
|||||||
func EndOfDay(t time.Time) time.Time
|
func EndOfDay(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/eMBOvmq5Ih1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/eMBOvmq5Ih1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -552,7 +550,7 @@ func main() {
|
|||||||
func EndOfWeek(t time.Time, endWith ...time.Weekday) time.Time
|
func EndOfWeek(t time.Time, endWith ...time.Weekday) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/i08qKXD9flf)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/i08qKXD9flf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -584,7 +582,7 @@ func main() {
|
|||||||
func EndOfMonth(t time.Time) time.Time
|
func EndOfMonth(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_GWh10B3Nqi)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_GWh10B3Nqi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -616,7 +614,7 @@ func main() {
|
|||||||
func EndOfYear(t time.Time) time.Time
|
func EndOfYear(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/G01cKlMCvNm)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/G01cKlMCvNm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -648,7 +646,7 @@ func main() {
|
|||||||
func GetNowDate() string
|
func GetNowDate() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/PvfkPpcpBBf)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/PvfkPpcpBBf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -677,7 +675,7 @@ func main() {
|
|||||||
func GetNowTime() string
|
func GetNowTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/l7BNxCkTmJS)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/l7BNxCkTmJS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -706,7 +704,7 @@ func main() {
|
|||||||
func GetNowDateTime() string
|
func GetNowDateTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/pI4AqngD0al)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pI4AqngD0al)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -735,7 +733,7 @@ func main() {
|
|||||||
func GetTodayStartTime() string
|
func GetTodayStartTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/84siyYF7t99)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/84siyYF7t99)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -764,7 +762,7 @@ func main() {
|
|||||||
func GetTodayEndTime() string
|
func GetTodayEndTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jjrLnfoqgn3)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jjrLnfoqgn3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -793,7 +791,7 @@ func main() {
|
|||||||
func GetZeroHourTimestamp() int64
|
func GetZeroHourTimestamp() int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/QmL2oIaGE3q)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/QmL2oIaGE3q)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -822,7 +820,7 @@ func main() {
|
|||||||
func GetNightTimestamp() int64
|
func GetNightTimestamp() int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/UolysR3MYP1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/UolysR3MYP1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -851,7 +849,7 @@ func main() {
|
|||||||
func FormatTimeToStr(t time.Time, format string, timezone ...string) string
|
func FormatTimeToStr(t time.Time, format string, timezone ...string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_Ia7M8H_OvE)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_Ia7M8H_OvE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -890,7 +888,7 @@ func main() {
|
|||||||
func FormatStrToTime(str, format string, timezone ...string) (time.Time, error)
|
func FormatStrToTime(str, format string, timezone ...string) (time.Time, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/1h9FwdU8ql4)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/1h9FwdU8ql4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -929,7 +927,7 @@ type theTime struct {
|
|||||||
func NewUnixNow() *theTime
|
func NewUnixNow() *theTime
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/U4PPx-9D0oz)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/U4PPx-9D0oz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -961,7 +959,7 @@ type theTime struct {
|
|||||||
func NewUnix(unix int64) *theTime
|
func NewUnix(unix int64) *theTime
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/psoSuh_kLRt)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/psoSuh_kLRt)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -993,7 +991,7 @@ type theTime struct {
|
|||||||
func NewFormat(t string) (*theTime, error)
|
func NewFormat(t string) (*theTime, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1025,7 +1023,7 @@ type theTime struct {
|
|||||||
func NewISO8601(iso8601 string) (*theTime, error)
|
func NewISO8601(iso8601 string) (*theTime, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1054,7 +1052,7 @@ func main() {
|
|||||||
func (t *theTime) ToUnix() int64
|
func (t *theTime) ToUnix() int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_LUiwAdocjy)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_LUiwAdocjy)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1083,7 +1081,7 @@ func main() {
|
|||||||
func (t *theTime) ToFormat() string
|
func (t *theTime) ToFormat() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1112,7 +1110,7 @@ func main() {
|
|||||||
func (t *theTime) ToFormatForTpl(tpl string) string
|
func (t *theTime) ToFormatForTpl(tpl string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nyXxXcQJ8L5)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nyXxXcQJ8L5)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1142,7 +1140,7 @@ func main() {
|
|||||||
func (t *theTime) ToIso8601() string
|
func (t *theTime) ToIso8601() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1172,7 +1170,7 @@ func main() {
|
|||||||
func IsLeapYear(year int) bool
|
func IsLeapYear(year int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/xS1eS2ejGew)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/xS1eS2ejGew)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1205,7 +1203,7 @@ func main() {
|
|||||||
func BetweenSeconds(t1 time.Time, t2 time.Time) int64
|
func BetweenSeconds(t1 time.Time, t2 time.Time) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/n3YDRyfyXJu)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/n3YDRyfyXJu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1242,7 +1240,7 @@ func main() {
|
|||||||
func DayOfYear(t time.Time) int
|
func DayOfYear(t time.Time) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/0hjqhTwFNlH)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/0hjqhTwFNlH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1283,7 +1281,7 @@ func main() {
|
|||||||
func IsWeekend(t time.Time) bool
|
func IsWeekend(t time.Time) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/cupRM5aZOIY)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/cupRM5aZOIY)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1323,7 +1321,7 @@ func main() {
|
|||||||
func NowDateOrTime(format string, timezone ...string) string
|
func NowDateOrTime(format string, timezone ...string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/EZ-begEjtT0)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/EZ-begEjtT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1357,7 +1355,7 @@ func main() {
|
|||||||
func Timestamp(timezone ...string) int64
|
func Timestamp(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/iU5b7Vvjx6x)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/iU5b7Vvjx6x)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1388,7 +1386,7 @@ func main() {
|
|||||||
func TimestampMilli(timezone ...string) int64
|
func TimestampMilli(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4gvEusOTu1T)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4gvEusOTu1T)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1418,7 +1416,7 @@ func main() {
|
|||||||
func TimestampMicro(timezone ...string) int64
|
func TimestampMicro(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/2maANglKHQE)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/2maANglKHQE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1448,7 +1446,7 @@ func main() {
|
|||||||
func TimestampNano(timezone ...string) int64
|
func TimestampNano(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/A9Oq_COrcCF)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/A9Oq_COrcCF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -47,11 +47,10 @@ import (
|
|||||||
- [WriteCsvFile](#WriteCsvFile)
|
- [WriteCsvFile](#WriteCsvFile)
|
||||||
- [WriteStringToFile](#WriteStringToFile)
|
- [WriteStringToFile](#WriteStringToFile)
|
||||||
- [WriteBytesToFile](#WriteBytesToFile)
|
- [WriteBytesToFile](#WriteBytesToFile)
|
||||||
|
- [ReadFile](#ReadFile)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="ClearFile">ClearFile</span>
|
### <span id="ClearFile">ClearFile</span>
|
||||||
@@ -64,7 +63,7 @@ import (
|
|||||||
func ClearFile(path string) error
|
func ClearFile(path string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/NRZ0ZT-G94H)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/NRZ0ZT-G94H)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -92,7 +91,7 @@ func main() {
|
|||||||
func CreateFile(path string) bool
|
func CreateFile(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/lDt8PEsTNKI)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/lDt8PEsTNKI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -118,7 +117,7 @@ func main() {
|
|||||||
func CreateDir(absPath string) error
|
func CreateDir(absPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/qUuCe1OGQnM)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qUuCe1OGQnM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -144,7 +143,7 @@ func main() {
|
|||||||
func CopyFile(srcPath string, dstPath string) error
|
func CopyFile(srcPath string, dstPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Jg9AMJMLrJi)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Jg9AMJMLrJi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -172,7 +171,7 @@ func main() {
|
|||||||
func CurrentPath() string
|
func CurrentPath() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/s74a9iBGcSw)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/s74a9iBGcSw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -198,7 +197,7 @@ func main() {
|
|||||||
func FileMode(path string) (fs.FileMode, error)
|
func FileMode(path string) (fs.FileMode, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/2l2hI42fA3p)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/2l2hI42fA3p)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -227,7 +226,7 @@ func main() {
|
|||||||
func MiMeType(file any) string
|
func MiMeType(file any) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/bd5sevSUZNu)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/bd5sevSUZNu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -258,7 +257,7 @@ func main() {
|
|||||||
func IsExist(path string) bool
|
func IsExist(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nKKXt8ZQbmh)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nKKXt8ZQbmh)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -285,7 +284,7 @@ func main() {
|
|||||||
func IsLink(path string) bool
|
func IsLink(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/TL-b-Kzvf44)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/TL-b-Kzvf44)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -311,7 +310,7 @@ func main() {
|
|||||||
func IsDir(path string) bool
|
func IsDir(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/WkVwEKqtOWk)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/WkVwEKqtOWk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -340,7 +339,7 @@ func main() {
|
|||||||
func ListFileNames(path string) ([]string, error)
|
func ListFileNames(path string) ([]string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Tjd7Y07rejl)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Tjd7Y07rejl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -366,7 +365,7 @@ func main() {
|
|||||||
func RemoveFile(path string) error
|
func RemoveFile(path string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/P2y0XW8a1SH)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/P2y0XW8a1SH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -394,7 +393,7 @@ func main() {
|
|||||||
func ReadFileToString(path string) (string, error)
|
func ReadFileToString(path string) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/cmfwp_5SQTp)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/cmfwp_5SQTp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -427,7 +426,7 @@ func main() {
|
|||||||
func ReadFileByLine(path string)([]string, error)
|
func ReadFileByLine(path string)([]string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/svJP_7ZrBrD)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/svJP_7ZrBrD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -461,7 +460,7 @@ func main() {
|
|||||||
func Zip(fpath string, destPath string) error
|
func Zip(fpath string, destPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/j-3sWBp8ik_P)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/j-3sWBp8ik_P)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -489,7 +488,7 @@ func main() {
|
|||||||
func ZipAppendEntry(fpath string, destPath string) error
|
func ZipAppendEntry(fpath string, destPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/cxvaT8TRNQp)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/cxvaT8TRNQp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -517,7 +516,7 @@ func main() {
|
|||||||
func UnZip(zipFile string, destPath string) error
|
func UnZip(zipFile string, destPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/g0w34kS7B8m)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/g0w34kS7B8m)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -545,7 +544,7 @@ func main() {
|
|||||||
func IsZipFile(filepath string) bool
|
func IsZipFile(filepath string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/9M0g2j_uF_e)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9M0g2j_uF_e)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -571,7 +570,7 @@ func main() {
|
|||||||
func FileSize(path string) (int64, error)
|
func FileSize(path string) (int64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/H9Z05uD-Jjc)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/H9Z05uD-Jjc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -603,7 +602,7 @@ func main() {
|
|||||||
func MTime(filepath string) (int64, error)
|
func MTime(filepath string) (int64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/s_Tl7lZoAaY)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/s_Tl7lZoAaY)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -635,7 +634,7 @@ func main() {
|
|||||||
func Sha(filepath string, shaType ...int) (string, error)
|
func Sha(filepath string, shaType ...int) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/VfEEcO2MJYf)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/VfEEcO2MJYf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -673,7 +672,7 @@ func main() {
|
|||||||
func ReadCsvFile(filepath string) ([][]string, error)
|
func ReadCsvFile(filepath string) ([][]string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/OExTkhGEd3_u)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/OExTkhGEd3_u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -705,7 +704,7 @@ func main() {
|
|||||||
func WriteCsvFile(filepath string, records [][]string, append bool) error
|
func WriteCsvFile(filepath string, records [][]string, append bool) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/dAXm58Q5U1o)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/dAXm58Q5U1o)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -754,7 +753,7 @@ func main() {
|
|||||||
func WriteBytesToFile(filepath string, content []byte) error
|
func WriteBytesToFile(filepath string, content []byte) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/s7QlDxMj3P8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/s7QlDxMj3P8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -803,7 +802,7 @@ func main() {
|
|||||||
func WriteStringToFile(filepath string, content string, append bool) error
|
func WriteStringToFile(filepath string, content string, append bool) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/GhLS6d8lH_g)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/GhLS6d8lH_g)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -841,3 +840,41 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="ReadFile">ReadFile</span>
|
||||||
|
|
||||||
|
<p>读取文件或者URL</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;"></span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/fileutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
reader, fn, err := ReadFile("https://httpbin.org/robots.txt")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer fn()
|
||||||
|
|
||||||
|
dat, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(string(dat))
|
||||||
|
// Output:
|
||||||
|
// User-agent: *
|
||||||
|
// Disallow: /deny
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -33,8 +33,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="Comma">Comma</span>
|
### <span id="Comma">Comma</span>
|
||||||
@@ -47,7 +45,7 @@ import (
|
|||||||
func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string
|
func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -83,7 +81,7 @@ func main() {
|
|||||||
func Pretty(v any) (string, error)
|
func Pretty(v any) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/YsciGj3FH2x)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/YsciGj3FH2x)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -122,7 +120,7 @@ func main() {
|
|||||||
func PrettyToWriter(v any, out io.Writer) error
|
func PrettyToWriter(v any, out io.Writer) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/LPLZ3lDi5ma)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/LPLZ3lDi5ma)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -165,7 +163,7 @@ func main() {
|
|||||||
func DecimalBytes(size float64, precision ...int) string
|
func DecimalBytes(size float64, precision ...int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/FPXs1suwRcs)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/FPXs1suwRcs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -204,7 +202,7 @@ func main() {
|
|||||||
func BinaryBytes(size float64, precision ...int) string
|
func BinaryBytes(size float64, precision ...int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/G9oHHMCAZxP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/G9oHHMCAZxP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -243,7 +241,7 @@ func main() {
|
|||||||
func ParseDecimalBytes(size string) (uint64, error)
|
func ParseDecimalBytes(size string) (uint64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Am98ybWjvjj)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Am98ybWjvjj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -282,7 +280,7 @@ func main() {
|
|||||||
func ParseBinaryBytes(size string) (uint64, error)
|
func ParseBinaryBytes(size string) (uint64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/69v1tTT62x8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/69v1tTT62x8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ import (
|
|||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
### <span id="After">After</span>
|
### <span id="After">After</span>
|
||||||
|
|
||||||
<p>创建一个函数,当他被调用n或更多次之后将马上触发fn</p>
|
<p>创建一个函数,当他被调用n或更多次之后将马上触发fn</p>
|
||||||
@@ -49,7 +47,7 @@ import (
|
|||||||
func After(n int, fn any) func(args ...any) []reflect.Value
|
func After(n int, fn any) func(args ...any) []reflect.Value
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -82,7 +80,7 @@ func main() {
|
|||||||
func Before(n int, fn any) func(args ...any) []reflect.Value
|
func Before(n int, fn any) func(args ...any) []reflect.Value
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/0HqUDIFZ3IL)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/0HqUDIFZ3IL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -119,7 +117,7 @@ type CurryFn[T any] func(...T) T
|
|||||||
func (cf CurryFn[T]) New(val T) func(...T) T
|
func (cf CurryFn[T]) New(val T) func(...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/5HopfDwANKX)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/5HopfDwANKX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -158,7 +156,7 @@ func main() {
|
|||||||
func Compose[T any](fnList ...func(...T) T) func(...T) T
|
func Compose[T any](fnList ...func(...T) T) func(...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/KKfugD4PKYF)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KKfugD4PKYF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -196,7 +194,7 @@ func main() {
|
|||||||
func Debounced(fn func(), duration time.Duration) func()
|
func Debounced(fn func(), duration time.Duration) func()
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/absuEGB_GN7)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/absuEGB_GN7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -246,7 +244,7 @@ func main() {
|
|||||||
func Delay(delay time.Duration, fn any, args ...any)
|
func Delay(delay time.Duration, fn any, args ...any)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Ivtc2ZE-Tye)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Ivtc2ZE-Tye)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -278,7 +276,7 @@ func main() {
|
|||||||
func Schedule(d time.Duration, fn any, args ...any) chan bool
|
func Schedule(d time.Duration, fn any, args ...any) chan bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/hbON-Xeyn5N)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/hbON-Xeyn5N)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -317,7 +315,7 @@ func main() {
|
|||||||
func Pipeline[T any](funcs ...func(T) T) func(T) T
|
func Pipeline[T any](funcs ...func(T) T) func(T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/mPdUVvj6HD6)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/mPdUVvj6HD6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -369,7 +367,7 @@ func (w *Watcher) GetElapsedTime() time.Duration
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/l2yrOpCLd1I)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/l2yrOpCLd1I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## API 文档:
|
## API 文档:
|
||||||
|
|
||||||
### <span id="MapTo">MapTo</span>
|
### <span id="MapTo">MapTo</span>
|
||||||
@@ -69,7 +67,7 @@ import (
|
|||||||
func MapTo(src any, dst any) error
|
func MapTo(src any, dst any) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/4K7KBEPgS5M)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4K7KBEPgS5M)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -126,7 +124,7 @@ func main() {
|
|||||||
func ForEach[K comparable, V any](m map[K]V, iteratee func(key K, value V))
|
func ForEach[K comparable, V any](m map[K]V, iteratee func(key K, value V))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/OaThj6iNVXK)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/OaThj6iNVXK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -167,7 +165,7 @@ func main() {
|
|||||||
func Filter[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
func Filter[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/fSvF3wxuNG7)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fSvF3wxuNG7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -212,7 +210,7 @@ func main() {
|
|||||||
func FilterByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
func FilterByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/7ov6BJHbVqh)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/7ov6BJHbVqh)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -250,7 +248,7 @@ func main() {
|
|||||||
func FilterByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
func FilterByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/P3-9MdcXegR)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/P3-9MdcXegR)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -288,7 +286,7 @@ func main() {
|
|||||||
func OmitBy[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
func OmitBy[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/YJM4Hj5hNwm)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/YJM4Hj5hNwm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -329,7 +327,7 @@ func main() {
|
|||||||
func OmitByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
func OmitByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jXGrWDBfSRp)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jXGrWDBfSRp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -367,7 +365,7 @@ func main() {
|
|||||||
func OmitByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
func OmitByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/XB7Y10uw20_U)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/XB7Y10uw20_U)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -405,7 +403,7 @@ func main() {
|
|||||||
func Intersect[K comparable, V any](maps ...map[K]V) map[K]V
|
func Intersect[K comparable, V any](maps ...map[K]V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Zld0oj3sjcC)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Zld0oj3sjcC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -460,7 +458,7 @@ func main() {
|
|||||||
func Keys[K comparable, V any](m map[K]V) []K
|
func Keys[K comparable, V any](m map[K]V) []K
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/xNB5bTb97Wd)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/xNB5bTb97Wd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -499,7 +497,7 @@ func main() {
|
|||||||
func Merge[K comparable, V any](maps ...map[K]V) map[K]V
|
func Merge[K comparable, V any](maps ...map[K]V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/H95LENF1uB-)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/H95LENF1uB-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -538,7 +536,7 @@ func main() {
|
|||||||
func Minus[K comparable, V any](mapA, mapB map[K]V) map[K]V
|
func Minus[K comparable, V any](mapA, mapB map[K]V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/3u5U9K7YZ9m)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/3u5U9K7YZ9m)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -580,7 +578,7 @@ func main() {
|
|||||||
func Values[K comparable, V any](m map[K]V) []V
|
func Values[K comparable, V any](m map[K]V) []V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/CBKdUc5FTW6)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/CBKdUc5FTW6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -617,7 +615,7 @@ func main() {
|
|||||||
func KeysBy[K comparable, V any, T any](m map[K]V, mapper func(item K) T) []T
|
func KeysBy[K comparable, V any, T any](m map[K]V, mapper func(item K) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/hI371iB8Up8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/hI371iB8Up8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -658,7 +656,7 @@ func main() {
|
|||||||
func ValuesBy[K comparable, V any, T any](m map[K]V, mapper func(item V) T) []T
|
func ValuesBy[K comparable, V any, T any](m map[K]V, mapper func(item V) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/sg9-oRidh8f)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/sg9-oRidh8f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -707,7 +705,7 @@ func main() {
|
|||||||
func MapKeys[K comparable, V any, T comparable](m map[K]V, iteratee func(key K, value V) T) map[T]V
|
func MapKeys[K comparable, V any, T comparable](m map[K]V, iteratee func(key K, value V) T) map[T]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/8scDxWeBDKd)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8scDxWeBDKd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -746,7 +744,7 @@ func main() {
|
|||||||
func MapValues[K comparable, V any, T any](m map[K]V, iteratee func(key K, value V) T) map[K]T
|
func MapValues[K comparable, V any, T any](m map[K]V, iteratee func(key K, value V) T) map[K]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/g92aY3fc7Iw)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/g92aY3fc7Iw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -789,7 +787,7 @@ type Entry[K comparable, V any] struct {
|
|||||||
func Entries[K comparable, V any](m map[K]V) []Entry[K, V]
|
func Entries[K comparable, V any](m map[K]V) []Entry[K, V]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Ltb11LNcElY)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Ltb11LNcElY)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -834,7 +832,7 @@ type Entry[K comparable, V any] struct {
|
|||||||
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
|
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/C8L4ul9TVwf)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/C8L4ul9TVwf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -868,7 +866,7 @@ func main() {
|
|||||||
func Transform[K1 comparable, V1 any, K2 comparable, V2 any](m map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2
|
func Transform[K1 comparable, V1 any, K2 comparable, V2 any](m map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/P6ovfToM3zj)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/P6ovfToM3zj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -907,7 +905,7 @@ func main() {
|
|||||||
func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
|
func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -962,7 +960,7 @@ if haskey {
|
|||||||
func HasKey[K comparable, V any](m map[K]V, key K) bool
|
func HasKey[K comparable, V any](m map[K]V, key K) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/isZZHOsDhFc)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/isZZHOsDhFc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1001,7 +999,7 @@ func main() {
|
|||||||
func NewConcurrentMap[K comparable, V any](shardCount int) *ConcurrentMap[K, V]
|
func NewConcurrentMap[K comparable, V any](shardCount int) *ConcurrentMap[K, V]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1027,7 +1025,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Set(key K, value V)
|
func (cm *ConcurrentMap[K, V]) Set(key K, value V)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1081,7 +1079,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Get(key K) (V, bool)
|
func (cm *ConcurrentMap[K, V]) Get(key K) (V, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1135,7 +1133,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) GetOrSet(key K, value V) (actual V, ok bool)
|
func (cm *ConcurrentMap[K, V]) GetOrSet(key K, value V) (actual V, ok bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/aDcDApOK01a)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/aDcDApOK01a)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1179,7 +1177,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Delete(key K)
|
func (cm *ConcurrentMap[K, V]) Delete(key K)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/uTIJZYhpVMS)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uTIJZYhpVMS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1225,7 +1223,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) GetAndDelete(key K) (actual V, ok bool)
|
func (cm *ConcurrentMap[K, V]) GetAndDelete(key K) (actual V, ok bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ZyxeIXSZUiM)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ZyxeIXSZUiM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1276,7 +1274,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Has(key K) bool
|
func (cm *ConcurrentMap[K, V]) Has(key K) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/C8L4ul9TVwf)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/C8L4ul9TVwf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1324,7 +1322,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Range(iterator func(key K, value V) bool)
|
func (cm *ConcurrentMap[K, V]) Range(iterator func(key K, value V) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/iqcy7P8P0Pr)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/iqcy7P8P0Pr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="../../styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="Average">Average</span>
|
### <span id="Average">Average</span>
|
||||||
@@ -64,7 +62,7 @@ import (
|
|||||||
func Average[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Average[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/HFd70x4DrMj)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HFd70x4DrMj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -99,7 +97,7 @@ func main() {
|
|||||||
func Exponent(x, n int64) int64
|
func Exponent(x, n int64) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Vv7LBwER-pz)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Vv7LBwER-pz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -135,7 +133,7 @@ func main() {
|
|||||||
func Fibonacci(first, second, n int) int
|
func Fibonacci(first, second, n int) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/IscseUNMuUc)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/IscseUNMuUc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -171,7 +169,7 @@ func main() {
|
|||||||
func Factorial(x uint) uint
|
func Factorial(x uint) uint
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/tt6LdOK67Nx)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tt6LdOK67Nx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -207,7 +205,7 @@ func main() {
|
|||||||
func Max[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Max[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/cN8DHI0rTkH)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/cN8DHI0rTkH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -240,7 +238,7 @@ func main() {
|
|||||||
func MaxBy[T any](slice []T, comparator func(T, T) bool) T
|
func MaxBy[T any](slice []T, comparator func(T, T) bool) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/pbe2MT-7DV2)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pbe2MT-7DV2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -284,7 +282,7 @@ func main() {
|
|||||||
func Min[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Min[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/pbe2MT-7DV2)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pbe2MT-7DV2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -317,7 +315,7 @@ func main() {
|
|||||||
func MinBy[T any](slice []T, comparator func(T, T) bool) T
|
func MinBy[T any](slice []T, comparator func(T, T) bool) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -361,7 +359,7 @@ func main() {
|
|||||||
func Percent(val, total float64, n int) float64
|
func Percent(val, total float64, n int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/s0NdFCtwuyd)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/s0NdFCtwuyd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -397,7 +395,7 @@ func main() {
|
|||||||
func RoundToFloat(x float64, n int) float64
|
func RoundToFloat(x float64, n int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ghyb528JRJL)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ghyb528JRJL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -433,7 +431,7 @@ func main() {
|
|||||||
func RoundToString(x float64, n int) string
|
func RoundToString(x float64, n int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/kZwpBRAcllO)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/kZwpBRAcllO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -469,7 +467,7 @@ func main() {
|
|||||||
func TruncRound(x float64, n int) float64
|
func TruncRound(x float64, n int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/aumarSHIGzP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/aumarSHIGzP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -505,7 +503,7 @@ func main() {
|
|||||||
func Range[T constraints.Integer | constraints.Float](start T, count int) []T
|
func Range[T constraints.Integer | constraints.Float](start T, count int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/9ke2opxa8ZP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9ke2opxa8ZP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -544,7 +542,7 @@ func main() {
|
|||||||
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T
|
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/akLWz0EqOSM)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/akLWz0EqOSM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -583,7 +581,7 @@ func main() {
|
|||||||
func AngleToRadian(angle float64) float64
|
func AngleToRadian(angle float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/CIvlICqrHql)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/CIvlICqrHql)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -619,7 +617,7 @@ func main() {
|
|||||||
func RadianToAngle(radian float64) float64
|
func RadianToAngle(radian float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/dQtmOTUOMgi)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/dQtmOTUOMgi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -655,7 +653,7 @@ func main() {
|
|||||||
func PointDistance(x1, y1, x2, y2 float64) float64
|
func PointDistance(x1, y1, x2, y2 float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/RrG4JIaziM8)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/RrG4JIaziM8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -685,7 +683,7 @@ func main() {
|
|||||||
func IsPrime(n int) bool
|
func IsPrime(n int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Rdd8UTHZJ7u)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Rdd8UTHZJ7u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -724,7 +722,7 @@ func main() {
|
|||||||
func GCD[T constraints.Integer](integers ...T) T
|
func GCD[T constraints.Integer](integers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/CiEceLSoAKB)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/CiEceLSoAKB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -766,7 +764,7 @@ func main() {
|
|||||||
func LCM[T constraints.Integer](integers ...T) T
|
func LCM[T constraints.Integer](integers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/EjcZxfY7G_g)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/EjcZxfY7G_g)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -802,7 +800,7 @@ func main() {
|
|||||||
func Cos(radian float64, precision ...int) float64
|
func Cos(radian float64, precision ...int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Sm89LoIfvFq)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Sm89LoIfvFq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -844,7 +842,7 @@ func main() {
|
|||||||
func Sin(radian float64, precision ...int) float64
|
func Sin(radian float64, precision ...int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/TWMQlMywDsP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/TWMQlMywDsP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -886,7 +884,7 @@ func main() {
|
|||||||
func Log(n, base float64) float64
|
func Log(n, base float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/_d4bi8oyhat)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_d4bi8oyhat)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -922,7 +920,7 @@ func main() {
|
|||||||
func Sum[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Sum[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/1To2ImAMJA7)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/1To2ImAMJA7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -955,7 +953,7 @@ func main() {
|
|||||||
func Abs[T constraints.Integer | constraints.Float](x T) T
|
func Abs[T constraints.Integer | constraints.Float](x T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/fsyBh1Os-1d)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fsyBh1Os-1d)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="ConvertMapToQueryString">ConvertMapToQueryString</span>
|
### <span id="ConvertMapToQueryString">ConvertMapToQueryString</span>
|
||||||
@@ -65,7 +63,7 @@ import (
|
|||||||
func ConvertMapToQueryString(param map[string]any) string
|
func ConvertMapToQueryString(param map[string]any) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jnNt_qoSnRi)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jnNt_qoSnRi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -100,7 +98,7 @@ func main() {
|
|||||||
func EncodeUrl(urlStr string) (string, error)
|
func EncodeUrl(urlStr string) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/bsZ6BRC4uKI)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/bsZ6BRC4uKI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -135,7 +133,7 @@ func main() {
|
|||||||
func GetInternalIp() string
|
func GetInternalIp() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/fxnna_LLD9u)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fxnna_LLD9u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -167,7 +165,7 @@ func main() {
|
|||||||
func GetIps() []string
|
func GetIps() []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/NUFfcEmukx1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/NUFfcEmukx1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -197,7 +195,7 @@ func main() {
|
|||||||
func GetMacAddrs() []string {
|
func GetMacAddrs() []string {
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/Rq9UUBS_Xp1)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Rq9UUBS_Xp1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -241,7 +239,7 @@ type PublicIpInfo struct {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/YDxIfozsRHR)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/YDxIfozsRHR)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -271,7 +269,7 @@ func main() {
|
|||||||
func GetRequestPublicIp(req *http.Request) string
|
func GetRequestPublicIp(req *http.Request) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/kxU-YDc_eBo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/kxU-YDc_eBo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -309,7 +307,7 @@ func main() {
|
|||||||
func IsPublicIP(IP net.IP) bool
|
func IsPublicIP(IP net.IP) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/nmktSQpJZnn)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nmktSQpJZnn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -346,7 +344,7 @@ func main() {
|
|||||||
func IsInternalIP(IP net.IP) bool
|
func IsInternalIP(IP net.IP) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/sYGhXbgO4Cb)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/sYGhXbgO4Cb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -390,7 +388,7 @@ type HttpRequest struct {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -447,7 +445,7 @@ func NewHttpClientWithConfig(config *HttpClientConfig) *HttpClient
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -478,7 +476,7 @@ func main() {
|
|||||||
func (client *HttpClient) SendRequest(request *HttpRequest) (*http.Response, error)
|
func (client *HttpClient) SendRequest(request *HttpRequest) (*http.Response, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -532,7 +530,7 @@ func main() {
|
|||||||
func (client *HttpClient) DecodeResponse(resp *http.Response, target any) error
|
func (client *HttpClient) DecodeResponse(resp *http.Response, target any) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -586,7 +584,7 @@ func main() {
|
|||||||
func StructToUrlValues(targetStruct any) url.Values
|
func StructToUrlValues(targetStruct any) url.Values
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/pFqMkM40w9z)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pFqMkM40w9z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -968,7 +966,7 @@ func main() {
|
|||||||
func IsPingConnected(host string) bool
|
func IsPingConnected(host string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/q8OzTijsA87)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/q8OzTijsA87)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1001,7 +999,7 @@ func main() {
|
|||||||
func IsTelnetConnected(host string, port string) bool
|
func IsTelnetConnected(host string, port string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/yiLCGtQv_ZG)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/yiLCGtQv_ZG)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="Of">Of</span>
|
### <span id="Of">Of</span>
|
||||||
@@ -44,7 +42,7 @@ import (
|
|||||||
func Of[T any](v T) *T
|
func Of[T any](v T) *T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/HFd70x4DrMj)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HFd70x4DrMj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -77,7 +75,7 @@ func main() {
|
|||||||
func Unwrap[T any](p *T) T
|
func Unwrap[T any](p *T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/cgeu3g7cjWb)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/cgeu3g7cjWb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -113,7 +111,7 @@ func main() {
|
|||||||
func ExtractPointer(value any) any
|
func ExtractPointer(value any) any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/D7HFjeWU2ZP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/D7HFjeWU2ZP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -148,7 +146,7 @@ func main() {
|
|||||||
UnwarpOr[T any](p *T, fallback T) T
|
UnwarpOr[T any](p *T, fallback T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/mmNaLC38W8C)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/mmNaLC38W8C)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -193,7 +191,7 @@ func main() {
|
|||||||
UnwarpOrDefault[T any](p *T) T
|
UnwarpOrDefault[T any](p *T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span class="run-container">[运行](https://go.dev/play/p/ZnGIHf8_o4E)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ZnGIHf8_o4E)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import (
|
|||||||
func RandBytes(length int) []byte
|
func RandBytes(length int) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/EkiLESeXf8d)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -72,7 +72,7 @@ func main() {
|
|||||||
func RandInt(min, max int) int
|
func RandInt(min, max int) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pXyyAAI5YxD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -98,7 +98,7 @@ func main() {
|
|||||||
func RandString(length int) string
|
func RandString(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/W2xvRUXA7Mi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -124,7 +124,7 @@ func main() {
|
|||||||
func RandUpper(length int) string
|
func RandUpper(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/29QfOh0DVuh)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -150,7 +150,7 @@ func main() {
|
|||||||
func RandLower(length int) string
|
func RandLower(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/XJtZ471cmtI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -176,7 +176,7 @@ func main() {
|
|||||||
func RandNumeral(length int) string
|
func RandNumeral(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/g4JWVpHsJcf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -202,7 +202,7 @@ func main() {
|
|||||||
func RandNumeralOrLetter(length int) string
|
func RandNumeralOrLetter(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/19CEQvpx2jD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -228,7 +228,7 @@ func main() {
|
|||||||
func UUIdV4() (string, error)
|
func UUIdV4() (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_Z9SFmr28ft)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -257,7 +257,7 @@ func main() {
|
|||||||
func RandUniqueIntSlice(n, min, max int) []int
|
func RandUniqueIntSlice(n, min, max int) []int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uBkRSOz73Ec)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -30,7 +30,8 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Document 文档
|
|
||||||
|
## 文档
|
||||||
|
|
||||||
### <span id="Context">Context</span>
|
### <span id="Context">Context</span>
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
func Context(ctx context.Context)
|
func Context(ctx context.Context)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/xnAOOXv9GkS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -89,7 +90,7 @@ func main() {
|
|||||||
type RetryFunc func() error
|
type RetryFunc func() error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -135,7 +136,7 @@ func main() {
|
|||||||
func RetryTimes(n uint)
|
func RetryTimes(n uint)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ssfVeU2SwLO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -178,7 +179,7 @@ func main() {
|
|||||||
func RetryDuration(d time.Duration)
|
func RetryDuration(d time.Duration)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -224,7 +225,7 @@ func main() {
|
|||||||
func Retry(retryFunc RetryFunc, opts ...Option) error
|
func Retry(retryFunc RetryFunc, opts ...Option) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -77,7 +77,7 @@ import (
|
|||||||
- [IsSortedByKey](#IsSortedByKey)
|
- [IsSortedByKey](#IsSortedByKey)
|
||||||
- [Sort](#Sort)
|
- [Sort](#Sort)
|
||||||
- [SortBy](#SortBy)
|
- [SortBy](#SortBy)
|
||||||
- [SortByField<sup>deprecated</sup>](#SortByField)
|
- [SortByField](#SortByField)
|
||||||
- [Some](#Some)
|
- [Some](#Some)
|
||||||
- [StringSlice<sup>deprecated</sup>](#StringSlice)
|
- [StringSlice<sup>deprecated</sup>](#StringSlice)
|
||||||
- [SymmetricDifference](#SymmetricDifference)
|
- [SymmetricDifference](#SymmetricDifference)
|
||||||
@@ -91,9 +91,11 @@ import (
|
|||||||
- [Without](#Without)
|
- [Without](#Without)
|
||||||
- [KeyBy](#KeyBy)
|
- [KeyBy](#KeyBy)
|
||||||
- [Join](#Join)
|
- [Join](#Join)
|
||||||
|
- [Partition](#Partition)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="AppendIfAbsent">AppendIfAbsent</span>
|
### <span id="AppendIfAbsent">AppendIfAbsent</span>
|
||||||
@@ -106,7 +108,7 @@ import (
|
|||||||
func AppendIfAbsent[T comparable](slice []T, item T) []T
|
func AppendIfAbsent[T comparable](slice []T, item T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/GNdv7Jg2Taj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -137,7 +139,7 @@ func main() {
|
|||||||
func Contain[T comparable](slice []T, target T) bool
|
func Contain[T comparable](slice []T, target T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_454yEHcNjf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -168,7 +170,7 @@ func main() {
|
|||||||
func ContainBy[T any](slice []T, predicate func(item T) bool) bool
|
func ContainBy[T any](slice []T, predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/49tkHfX4GNc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -213,7 +215,7 @@ func main() {
|
|||||||
func ContainSubSlice[T comparable](slice, subSlice []T) bool
|
func ContainSubSlice[T comparable](slice, subSlice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/bcuQ3UT6Sev)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -244,7 +246,7 @@ func main() {
|
|||||||
func Chunk[T any](slice []T, size int) [][]T
|
func Chunk[T any](slice []T, size int) [][]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/b4Pou5j2L_C)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -286,7 +288,7 @@ func main() {
|
|||||||
func Compact[T comparable](slice []T) []T
|
func Compact[T comparable](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pO5AnxEr3TK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -323,7 +325,7 @@ func main() {
|
|||||||
func Concat[T any](slice []T, slices ...[]T) []T
|
func Concat[T any](slice []T, slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/gPt-q7zr5mk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -354,7 +356,7 @@ func main() {
|
|||||||
func Count[T comparable](slice []T, item T) int
|
func Count[T comparable](slice []T, item T) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Mj4oiEnQvRJ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -387,7 +389,7 @@ func main() {
|
|||||||
func CountBy[T any](slice []T, predicate func(index int, item T) bool) int
|
func CountBy[T any](slice []T, predicate func(index int, item T) bool) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tHOccTMDZCC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -421,7 +423,7 @@ func main() {
|
|||||||
func Difference[T comparable](slice, comparedSlice []T) []T
|
func Difference[T comparable](slice, comparedSlice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/VXvadzLzhDa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -452,7 +454,7 @@ func main() {
|
|||||||
func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/DiivgwM5OnC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -487,7 +489,7 @@ func main() {
|
|||||||
func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
|
func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/v2U2deugKuV)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -522,7 +524,7 @@ func main() {
|
|||||||
func DeleteAt[T any](slice []T, start int, end ...int)
|
func DeleteAt[T any](slice []T, start int, end ...int)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pJ-d6MUWcvK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -557,7 +559,7 @@ func main() {
|
|||||||
func Drop[T any](slice []T, n int) []T
|
func Drop[T any](slice []T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jnPO2yQsT8H)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -594,7 +596,7 @@ func main() {
|
|||||||
func DropRight[T any](slice []T, n int) []T
|
func DropRight[T any](slice []T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8bcXvywZezG)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -631,7 +633,7 @@ func main() {
|
|||||||
func DropWhile[T any](slice []T, predicate func(item T) bool) []T
|
func DropWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4rt252UV_qs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -671,7 +673,7 @@ func main() {
|
|||||||
func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T
|
func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/6wyK3zMY56e)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -713,7 +715,7 @@ func main() {
|
|||||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/R8U6Sl-j8cD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -747,7 +749,7 @@ func main() {
|
|||||||
func Equal[T comparable](slice1, slice2 []T) bool
|
func Equal[T comparable](slice1, slice2 []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/WcRQJ37ifPa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -782,7 +784,7 @@ func main() {
|
|||||||
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/b9iygtgsHI1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -817,7 +819,7 @@ func main() {
|
|||||||
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/SdPna-7qK4T)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -851,7 +853,7 @@ func main() {
|
|||||||
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/CBKeBoHVLgq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -887,7 +889,7 @@ func main() {
|
|||||||
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)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/n1lysBYl-GB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -923,7 +925,7 @@ func main() {
|
|||||||
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/FFDPV_j7URd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -959,7 +961,7 @@ func main() {
|
|||||||
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)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8iqomzyCl_s)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -995,7 +997,7 @@ func main() {
|
|||||||
func Flatten(slice any) any
|
func Flatten(slice any) any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/hYa3cBEevtm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1025,7 +1027,7 @@ func main() {
|
|||||||
func FlattenDeep(slice any) any
|
func FlattenDeep(slice any) any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/yjYNHPyCFaF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1055,7 +1057,7 @@ func main() {
|
|||||||
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/DrPaa4YsHRF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1090,7 +1092,7 @@ func main() {
|
|||||||
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool)
|
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qScs39f3D9W)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1128,7 +1130,7 @@ func main() {
|
|||||||
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/QVkPxzPR0iA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1164,7 +1166,7 @@ func main() {
|
|||||||
func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T
|
func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ApCvMNTLO8a)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1198,7 +1200,7 @@ func main() {
|
|||||||
func IntSlice(slice any) []int
|
func IntSlice(slice any) []int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/UQDj-on9TGN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1227,7 +1229,7 @@ func main() {
|
|||||||
func InterfaceSlice(slice any) []any
|
func InterfaceSlice(slice any) []any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/FdQXF0Vvqs-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1256,7 +1258,7 @@ func main() {
|
|||||||
func Intersection[T comparable](slices ...[]T) []T
|
func Intersection[T comparable](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/anJXfB5wq_t)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1287,7 +1289,7 @@ func main() {
|
|||||||
func InsertAt[T any](slice []T, index int, value any) []T
|
func InsertAt[T any](slice []T, index int, value any) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/hMLNxPEGJVE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1327,7 +1329,7 @@ func main() {
|
|||||||
func IndexOf[T comparable](slice []T, item T) int
|
func IndexOf[T comparable](slice []T, item T) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/MRN1f0FpABb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1360,7 +1362,7 @@ func main() {
|
|||||||
func LastIndexOf[T comparable](slice []T, item T) int
|
func LastIndexOf[T comparable](slice []T, item T) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/DokM4cf1IKH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1393,7 +1395,7 @@ func main() {
|
|||||||
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/biaTefqPquw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1427,7 +1429,7 @@ func main() {
|
|||||||
func FilterMap[T any, U any](slice []T, iteratee func(index int, item T) (U, bool)) []U
|
func FilterMap[T any, U any](slice []T, iteratee func(index int, item T) (U, bool)) []U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/J94SZ_9MiIe)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1464,7 +1466,7 @@ func main() {
|
|||||||
func FlatMap[T any, U any](slice []T, iteratee func(index int, item T) []U) []U
|
func FlatMap[T any, U any](slice []T, iteratee func(index int, item T) []U) []U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_QARWlWs1N_F)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1497,7 +1499,7 @@ func main() {
|
|||||||
func Merge[T any](slices ...[]T) []T
|
func Merge[T any](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/lbjFp784r9N)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1528,7 +1530,7 @@ func main() {
|
|||||||
func Reverse[T any](slice []T)
|
func Reverse[T any](slice []T)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8uI8f1lwNrQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1558,7 +1560,7 @@ func main() {
|
|||||||
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/_RfXJJWIsIm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1592,7 +1594,7 @@ func main() {
|
|||||||
func ReduceBy[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
func ReduceBy[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/YKDpLi7gtee)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1628,7 +1630,7 @@ func main() {
|
|||||||
func ReduceRight[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
func ReduceRight[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qT9dZC03A1K)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1658,7 +1660,7 @@ func main() {
|
|||||||
func Replace[T comparable](slice []T, old T, new T, n int) []T
|
func Replace[T comparable](slice []T, old T, new T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/P5mZp7IhOFo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1700,7 +1702,7 @@ func main() {
|
|||||||
func ReplaceAll[T comparable](slice []T, old T, new T) []T
|
func ReplaceAll[T comparable](slice []T, old T, new T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/CzqXMsuYUrx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1728,7 +1730,7 @@ func main() {
|
|||||||
func Repeat[T any](item T, n int) []T
|
func Repeat[T any](item T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1756,7 +1758,7 @@ func main() {
|
|||||||
func Shuffle[T any](slice []T) []T
|
func Shuffle[T any](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/YHvhnWGU3Ge)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1785,7 +1787,7 @@ func main() {
|
|||||||
func IsAscending[T constraints.Ordered](slice []T) bool
|
func IsAscending[T constraints.Ordered](slice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9CtsFjet4SH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1819,7 +1821,7 @@ func main() {
|
|||||||
func IsDescending[T constraints.Ordered](slice []T) bool
|
func IsDescending[T constraints.Ordered](slice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/U_LljFXma14)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1853,7 +1855,7 @@ func main() {
|
|||||||
func IsSorted[T constraints.Ordered](slice []T) bool
|
func IsSorted[T constraints.Ordered](slice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/nCE8wPLwSA-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1887,7 +1889,7 @@ func main() {
|
|||||||
func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
|
func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tUoGB7DOHI4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1927,7 +1929,7 @@ func main() {
|
|||||||
func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
|
func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/V9AVjzf_4Fk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1964,7 +1966,7 @@ func main() {
|
|||||||
func SortBy[T any](slice []T, less func(a, b T) bool)
|
func SortBy[T any](slice []T, less func(a, b T) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/DAhLQSZEumm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2001,9 +2003,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="SortByField">SortByField (已弃用: 请使用 Sort 或 SortBy 代替该方法)</span>
|
### <span id="SortByField">SortByField</span>
|
||||||
|
|
||||||
<p>按字段对结构切片进行排序。slice元素应为struct,字段类型应为int、uint、string或bool。 默认排序类型是升序(asc),如果是降序,设置 sortType 为 desc</p>
|
<p>按字段对结构体切片进行排序。slice元素应为struct,排序字段field类型应为int、uint、string或bool。 默认排序类型是升序(asc),如果是降序,设置 sortType 为 desc</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -2011,7 +2013,7 @@ func main() {
|
|||||||
func SortByField(slice any, field string, sortType ...string) error
|
func SortByField(slice any, field string, sortType ...string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fU1prOBP9p1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2052,7 +2054,7 @@ func main() {
|
|||||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4pO9Xf9NDGS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2086,7 +2088,7 @@ func main() {
|
|||||||
func StringSlice(slice any) []string
|
func StringSlice(slice any) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/W0TZDWCPFcI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2115,7 +2117,7 @@ func main() {
|
|||||||
func SymmetricDifference[T comparable](slices ...[]T) []T
|
func SymmetricDifference[T comparable](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2146,7 +2148,7 @@ func main() {
|
|||||||
func ToSlice[T any](items ...T) []T
|
func ToSlice[T any](items ...T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/YzbzVq5kscN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2174,7 +2176,7 @@ func main() {
|
|||||||
func ToSlicePointer[T any](items ...T) []*T
|
func ToSlicePointer[T any](items ...T) []*T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/gx4tr6_VXSF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2209,7 +2211,7 @@ func main() {
|
|||||||
func Unique[T comparable](slice []T) []T
|
func Unique[T comparable](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/AXw0R3ZTE6a)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2236,7 +2238,7 @@ func main() {
|
|||||||
func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
|
func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/UR323iZLDpv)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2267,7 +2269,7 @@ func main() {
|
|||||||
func Union[T comparable](slices ...[]T) []T
|
func Union[T comparable](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/hfXV1iRIZOf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2298,7 +2300,7 @@ func main() {
|
|||||||
func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
|
func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HGKHfxKQsFi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2323,7 +2325,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="UpdateAt">UpdateAt</span>
|
### <span id="UpdateAt">UpdateAt</span>
|
||||||
|
|
||||||
<p>更新索引处的切片元素。 如果index < 0或 index >= len(slice),将返回错误</p>
|
<p>更新索引处的切片元素。 如果index < 0或 index <= len(slice),将返回错误</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -2331,7 +2333,7 @@ func main() {
|
|||||||
func UpdateAt[T any](slice []T, index int, value T) []T
|
func UpdateAt[T any](slice []T, index int, value T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/f3mh2KloWVm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2371,7 +2373,7 @@ func main() {
|
|||||||
func Without[T comparable](slice []T, items ...T) []T
|
func Without[T comparable](slice []T, items ...T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/bwhEXEypThg)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2399,7 +2401,7 @@ func main() {
|
|||||||
func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
|
func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/uXod2LWD1Kg)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2429,7 +2431,7 @@ func main() {
|
|||||||
func Join[T any](s []T, separator string) string
|
func Join[T any](s []T, separator string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/huKzqwNDD7V)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2451,3 +2453,39 @@ func main() {
|
|||||||
// 1-2-3-4-5
|
// 1-2-3-4-5
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="Partition">Partition</span>
|
||||||
|
|
||||||
|
<p>根据给定的predicate判断函数分组切片元素。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Partition[T any](slice []T, predicates ...func(item T) bool) [][]T
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/lkQ3Ri2NQhV)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
|
result1 := slice.Partition(nums)
|
||||||
|
result2 := slice.Partition(nums, func(n int) bool { return n%2 == 0 })
|
||||||
|
result3 := slice.Partition(nums, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 })
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// [[1 2 3 4 5]]
|
||||||
|
// [[2 4] [1 3 5]]
|
||||||
|
// [[1 2] [3 4] [5]]
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -63,7 +63,7 @@ import (
|
|||||||
func Of[T any](elems ...T) stream[T]
|
func Of[T any](elems ...T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jI6_iZZuVFE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -93,7 +93,7 @@ func main() {
|
|||||||
func FromSlice[T any](source []T) stream[T]
|
func FromSlice[T any](source []T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/wywTO0XZtI4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -123,7 +123,7 @@ func main() {
|
|||||||
func FromChannel[T any](source <-chan T) stream[T]
|
func FromChannel[T any](source <-chan T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9TZYugGMhXZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -161,7 +161,7 @@ func main() {
|
|||||||
func FromRange[T constraints.Integer | constraints.Float](start, end, step T) stream[T]
|
func FromRange[T constraints.Integer | constraints.Float](start, end, step T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9Ex1-zcg-B-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -190,7 +190,7 @@ func main() {
|
|||||||
func Generate[T any](generator func() func() (item T, ok bool)) stream[T]
|
func Generate[T any](generator func() func() (item T, ok bool)) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/rkOWL1yA3j9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -230,7 +230,7 @@ func main() {
|
|||||||
func Concat[T any](a, b stream[T]) stream[T]
|
func Concat[T any](a, b stream[T]) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HM4OlYk_OUC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -263,7 +263,7 @@ func main() {
|
|||||||
func (s stream[T]) Distinct() stream[T]
|
func (s stream[T]) Distinct() stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/eGkOSrm64cB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -297,7 +297,7 @@ func main() {
|
|||||||
func (s stream[T]) Filter(predicate func(item T) bool) stream[T]
|
func (s stream[T]) Filter(predicate func(item T) bool) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/MFlSANo-buc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -331,7 +331,7 @@ func main() {
|
|||||||
func (s stream[T]) Map(mapper func(item T) T) stream[T]
|
func (s stream[T]) Map(mapper func(item T) T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/OtNQUImdYko)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -365,7 +365,7 @@ func main() {
|
|||||||
func (s stream[T]) Peek(consumer func(item T)) stream[T]
|
func (s stream[T]) Peek(consumer func(item T)) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/u1VNzHs6cb2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -402,7 +402,7 @@ func main() {
|
|||||||
func (s stream[T]) Skip(n int) stream[T]
|
func (s stream[T]) Skip(n int) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fNdHbqjahum)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -441,7 +441,7 @@ func main() {
|
|||||||
func (s stream[T]) Limit(maxSize int) stream[T]
|
func (s stream[T]) Limit(maxSize int) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qsO4aniDcGf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -480,7 +480,7 @@ func main() {
|
|||||||
func (s stream[T]) Reverse() stream[T]
|
func (s stream[T]) Reverse() stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/A8_zkJnLHm4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -510,7 +510,7 @@ func main() {
|
|||||||
func (s stream[T]) Range(start, end int) stream[T]
|
func (s stream[T]) Range(start, end int) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/indZY5V2f4j)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -549,7 +549,7 @@ func main() {
|
|||||||
func (s stream[T]) Sorted(less func(a, b T) bool) stream[T]
|
func (s stream[T]) Sorted(less func(a, b T) bool) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/XXtng5uonFj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -581,7 +581,7 @@ func main() {
|
|||||||
func (s stream[T]) ForEach(action func(item T))
|
func (s stream[T]) ForEach(action func(item T))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Dsm0fPqcidk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -614,7 +614,7 @@ func main() {
|
|||||||
func (s stream[T]) Reduce(initial T, accumulator func(a, b T) T) T
|
func (s stream[T]) Reduce(initial T, accumulator func(a, b T) T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/6uzZjq_DJLU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -646,7 +646,7 @@ func main() {
|
|||||||
func (s stream[T]) FindFirst() (T, bool)
|
func (s stream[T]) FindFirst() (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9xEf0-6C1e3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -678,7 +678,7 @@ func main() {
|
|||||||
func (s stream[T]) FindLast() (T, bool)
|
func (s stream[T]) FindLast() (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/WZD2rDAW-2h)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -710,7 +710,7 @@ func main() {
|
|||||||
func (s stream[T]) Max(less func(a, b T) bool) (T, bool)
|
func (s stream[T]) Max(less func(a, b T) bool) (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/fm-1KOPtGzn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -734,7 +734,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="Min">Min</span>
|
### <span id="Min">Min</span>
|
||||||
|
|
||||||
<p>根据提供的less函数返回stream的最小元素。less函数: a < b</p>
|
<p>根据提供的less函数返回stream的最小元素。less函数: a < b</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -742,7 +742,7 @@ func main() {
|
|||||||
func (s stream[T]) Min(less func(a, b T) bool) (T, bool)
|
func (s stream[T]) Min(less func(a, b T) bool) (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/vZfIDgGNRe_0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -774,7 +774,7 @@ func main() {
|
|||||||
func (s stream[T]) AllMatch(predicate func(item T) bool) bool
|
func (s stream[T]) AllMatch(predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/V5TBpVRs-Cx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -812,7 +812,7 @@ func main() {
|
|||||||
func (s stream[T]) AnyMatch(predicate func(item T) bool) bool
|
func (s stream[T]) AnyMatch(predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/PTCnWn4OxSn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -850,7 +850,7 @@ func main() {
|
|||||||
func (s stream[T]) NoneMatch(predicate func(item T) bool) bool
|
func (s stream[T]) NoneMatch(predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/iWS64pL1oo3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -888,7 +888,7 @@ func main() {
|
|||||||
func (s stream[T]) Count() int
|
func (s stream[T]) Count() int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/r3koY6y_Xo-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -919,7 +919,7 @@ func main() {
|
|||||||
func (s stream[T]) ToSlice() []T
|
func (s stream[T]) ToSlice() []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/jI6_iZZuVFE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
# Field
|
# Structs
|
||||||
|
|
||||||
Field 包封装了一个抽象的`Field`结构体,提供了操作`struct`属性的相关函数
|
structs 包封装了一个抽象的`Struct`结构体,提供了操作`struct`的相关函数
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 源码:
|
## 源码:
|
||||||
|
|
||||||
|
- [https://github.com/duke-git/lancet/blob/main/structs/struct.go](https://github.com/duke-git/lancet/blob/main/structs/struct.go)
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/structs/field.go](https://github.com/duke-git/lancet/blob/main/structs/field.go)
|
- [https://github.com/duke-git/lancet/blob/main/structs/field.go](https://github.com/duke-git/lancet/blob/main/structs/field.go)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
@@ -21,6 +23,12 @@ import (
|
|||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 目录:
|
## 目录:
|
||||||
|
|
||||||
|
- [New](#New)
|
||||||
|
- [ToMap](#ToMap)
|
||||||
|
- [Fields](#Fields)
|
||||||
|
- [Field](#Field)
|
||||||
|
- [IsStruct](#IsStruct)
|
||||||
- [Tag](#Tag)
|
- [Tag](#Tag)
|
||||||
- [Name](#Name)
|
- [Name](#Name)
|
||||||
- [Value](#Value)
|
- [Value](#Value)
|
||||||
@@ -30,17 +38,190 @@ import (
|
|||||||
- [IsZero](#IsZero)
|
- [IsZero](#IsZero)
|
||||||
- [IsSlice](#IsSlice)
|
- [IsSlice](#IsSlice)
|
||||||
|
|
||||||
> 注意:由于`Field`继承于`Struct`,所以同样拥有`Struct`所有方法,如下:
|
|
||||||
|
|
||||||
- [ToMap](https://github.com/duke-git/lancet/blob/main/docs/structs/struct_zh-CN.md#ToMap)
|
|
||||||
- [Fields](https://github.com/duke-git/lancet/blob/main/docs/structs/struct_zh-CN.md#Fields)
|
|
||||||
- [Field](https://github.com/duke-git/lancet/blob/main/docs/structs/struct_zh-CN.md#Field)
|
|
||||||
- [IsStruct](https://github.com/duke-git/lancet/blob/main/docs/structs/struct_zh-CN.md#IsStruct)
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## API 文档:
|
## API 文档:
|
||||||
|
|
||||||
|
### <span id="New">New</span>
|
||||||
|
|
||||||
|
<p>`Struct`结构体的构造函数</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func New(value any, tagName ...string) *Struct
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
// to do something
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="ToMap">ToMap</span>
|
||||||
|
|
||||||
|
<p>将一个合法的struct对象转换为map[string]any</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) ToMap() (map[string]any, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>除此之外,提供一个便捷的静态方法 ToMap</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func ToMap(v any) (map[string]any, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s1 := structs.New(p1)
|
||||||
|
m1, _ := s1.ToMap()
|
||||||
|
|
||||||
|
fmt.Println(m1)
|
||||||
|
|
||||||
|
// 如果不需要Struct更多的方法,可以直接使用ToMap
|
||||||
|
m2, _ := structs.ToMap(p1)
|
||||||
|
|
||||||
|
fmt.Println(m2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// map[name:11]
|
||||||
|
// map[name:11]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Fields">Fields</span>
|
||||||
|
|
||||||
|
<p>获取一个struct对象的属性列表</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) Fields() []*Field
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
fields := s.Fields()
|
||||||
|
|
||||||
|
fmt.Println(len(fields))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Field">Field</span>
|
||||||
|
|
||||||
|
<p>根据属性名获取一个struct对象的属性</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) Field(name string) *Field
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
f := s.Field("Name")
|
||||||
|
|
||||||
|
fmt.Println(f.Value())
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 11
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsStruct">IsStruct</span>
|
||||||
|
|
||||||
|
<p>判断是否为一个合法的struct对象</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) IsStruct() bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
|
||||||
|
fmt.Println(s.IsStruct())
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### <span id="Tag">Tag</span>
|
### <span id="Tag">Tag</span>
|
||||||
|
|
||||||
<p>获取`Field`的`Tag`,默认的tag key是json</p>
|
<p>获取`Field`的`Tag`,默认的tag key是json</p>
|
||||||
@@ -49,6 +49,7 @@ import (
|
|||||||
- [StringToBytes](#StringToBytes)
|
- [StringToBytes](#StringToBytes)
|
||||||
- [BytesToString](#BytesToString)
|
- [BytesToString](#BytesToString)
|
||||||
- [IsBlank](#IsBlank)
|
- [IsBlank](#IsBlank)
|
||||||
|
- [IsNotBlank](#IsNotBlank)
|
||||||
- [HasPrefixAny](#HasPrefixAny)
|
- [HasPrefixAny](#HasPrefixAny)
|
||||||
- [HasSuffixAny](#HasSuffixAny)
|
- [HasSuffixAny](#HasSuffixAny)
|
||||||
- [IndexOffset](#IndexOffset)
|
- [IndexOffset](#IndexOffset)
|
||||||
@@ -62,7 +63,7 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Documentation 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="After">After</span>
|
### <span id="After">After</span>
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ import (
|
|||||||
func After(s, char string) string
|
func After(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/RbCOQqCDA7m)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -114,7 +115,7 @@ func main() {
|
|||||||
func AfterLast(s, char string) string
|
func AfterLast(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/1TegARrb8Yn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -154,7 +155,7 @@ func main() {
|
|||||||
func Before(s, char string) string
|
func Before(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/JAWTZDS4F5w)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -191,7 +192,7 @@ func main() {
|
|||||||
func BeforeLast(s, char string) string
|
func BeforeLast(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pJfXXAoG_Te)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -228,7 +229,7 @@ func main() {
|
|||||||
func CamelCase(s string) string
|
func CamelCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9eXP3tn2tUy)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -263,7 +264,7 @@ func main() {
|
|||||||
func KebabCase(s string) string
|
func KebabCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/dcZM9Oahw-Y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -298,7 +299,7 @@ func main() {
|
|||||||
func UpperKebabCase(s string) string
|
func UpperKebabCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/zDyKNneyQXk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -333,7 +334,7 @@ func main() {
|
|||||||
func Capitalize(s string) string
|
func Capitalize(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/2OAjgbmAqHZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -368,7 +369,7 @@ func main() {
|
|||||||
func IsString(v any) bool
|
func IsString(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/IOgq7oF9ERm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -408,7 +409,7 @@ func main() {
|
|||||||
func LowerFirst(s string) string
|
func LowerFirst(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/CbzAyZmtJwL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -442,7 +443,7 @@ func main() {
|
|||||||
func UpperFirst(s string) string
|
func UpperFirst(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/sBbBxRbs8MM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -476,7 +477,7 @@ func main() {
|
|||||||
func Pad(source string, size int, padStr string) string
|
func Pad(source string, size int, padStr string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/NzImQq-VF8q)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -521,7 +522,7 @@ func main() {
|
|||||||
func PadEnd(source string, size int, padStr string) string
|
func PadEnd(source string, size int, padStr string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/9xP8rN0vz--)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -567,7 +568,7 @@ func main() {
|
|||||||
func PadStart(source string, size int, padStr string) string
|
func PadStart(source string, size int, padStr string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/xpTfzArDfvT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -613,7 +614,7 @@ func main() {
|
|||||||
func Reverse(s string) string
|
func Reverse(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/adfwalJiecD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -644,7 +645,7 @@ func main() {
|
|||||||
func SnakeCase(s string) string
|
func SnakeCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tgzQG11qBuN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -676,10 +677,10 @@ func main() {
|
|||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func SnakeCase(s string) string
|
func UpperSnakeCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4COPHpnLx38)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -714,7 +715,7 @@ func main() {
|
|||||||
func SplitEx(s, sep string, removeEmptyString bool) []string
|
func SplitEx(s, sep string, removeEmptyString bool) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Us-ySSbWh-3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -755,7 +756,7 @@ func main() {
|
|||||||
func Substring(s string, offset int, length uint) string
|
func Substring(s string, offset int, length uint) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/q3sM6ehnPDp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -798,7 +799,7 @@ func main() {
|
|||||||
func Wrap(str string, wrapWith string) string
|
func Wrap(str string, wrapWith string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KoZOlZDDt9y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -825,7 +826,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="Wrap">Wrap</span>
|
### <span id="Unwrap">Unwrap</span>
|
||||||
|
|
||||||
<p>用另一个字符串解开包裹一个字符串。</p>
|
<p>用另一个字符串解开包裹一个字符串。</p>
|
||||||
|
|
||||||
@@ -835,7 +836,7 @@ func main() {
|
|||||||
func Unwrap(str string, wrapToken string) string
|
func Unwrap(str string, wrapToken string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Ec2q4BzCpG-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -875,7 +876,7 @@ func main() {
|
|||||||
func SplitWords(s string) []string
|
func SplitWords(s string) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KLiX4WiysMM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -918,7 +919,7 @@ func main() {
|
|||||||
func WordCount(s string) int
|
func WordCount(s string) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/bj7_odx3vRf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -961,7 +962,7 @@ func main() {
|
|||||||
func RemoveNonPrintable(str string) string
|
func RemoveNonPrintable(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/og47F5x_jTZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -992,7 +993,7 @@ func main() {
|
|||||||
func StringToBytes(str string) (b []byte)
|
func StringToBytes(str string) (b []byte)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/7OyFBrf9AxA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1022,7 +1023,7 @@ func main() {
|
|||||||
func BytesToString(bytes []byte) string
|
func BytesToString(bytes []byte) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/6c68HRvJecH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1051,7 +1052,7 @@ func main() {
|
|||||||
func IsBlank(str string) bool
|
func IsBlank(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/6zXRH_c0Qd3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1075,6 +1076,45 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="IsNotBlank">IsNotBlank</span>
|
||||||
|
|
||||||
|
<p>Checks if a string is not whitespace or not empty.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsNotBlank(str string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/strutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := IsNotBlank("")
|
||||||
|
result2 := IsNotBlank(" ")
|
||||||
|
result3 := IsNotBlank("\t\v\f\n")
|
||||||
|
result4 := IsNotBlank(" 中文")
|
||||||
|
result5 := IsNotBlank(" world ")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
fmt.Println(result5)
|
||||||
|
// Output:
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### <span id="HasPrefixAny">HasPrefixAny</span>
|
### <span id="HasPrefixAny">HasPrefixAny</span>
|
||||||
|
|
||||||
<p>检查字符串是否以指定字符串数组中的任何一个开头。</p>
|
<p>检查字符串是否以指定字符串数组中的任何一个开头。</p>
|
||||||
@@ -1085,7 +1125,7 @@ func main() {
|
|||||||
func HasPrefixAny(str string, prefixes []string) bool
|
func HasPrefixAny(str string, prefixes []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8UUTl2C5slo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1116,7 +1156,7 @@ func main() {
|
|||||||
func HasSuffixAny(str string, suffixes []string) bool
|
func HasSuffixAny(str string, suffixes []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/sKWpCQdOVkx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1147,7 +1187,7 @@ func main() {
|
|||||||
func IndexOffset(str string, substr string, idxFrom int) int
|
func IndexOffset(str string, substr string, idxFrom int) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qZo4lV2fomB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1189,7 +1229,7 @@ func main() {
|
|||||||
func ReplaceWithMap(str string, replaces map[string]string) string
|
func ReplaceWithMap(str string, replaces map[string]string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/h3t7CNj2Vvu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1222,7 +1262,7 @@ func main() {
|
|||||||
func Trim(str string, characterMask ...string) string
|
func Trim(str string, characterMask ...string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Y0ilP0NRV3j)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1259,7 +1299,7 @@ func main() {
|
|||||||
func SplitAndTrim(str, delimiter string, characterMask ...string) []string
|
func SplitAndTrim(str, delimiter string, characterMask ...string) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ZNL6o4SkYQ7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1292,7 +1332,7 @@ func main() {
|
|||||||
func HideString(origin string, start, end int, replaceChar string) string
|
func HideString(origin string, start, end int, replaceChar string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/pzbaIVCTreZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1331,7 +1371,7 @@ func main() {
|
|||||||
func ContainsAll(str string, substrs []string) bool
|
func ContainsAll(str string, substrs []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KECtK2Os4zq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1364,7 +1404,7 @@ func main() {
|
|||||||
func ContainsAny(str string, substrs []string) bool
|
func ContainsAny(str string, substrs []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/dZGSSMB3LXE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1400,7 +1440,7 @@ func main() {
|
|||||||
func RemoveWhiteSpace(str string, repalceAll bool) string
|
func RemoveWhiteSpace(str string, repalceAll bool) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HzLC9vsTwkf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -46,7 +46,7 @@ import (
|
|||||||
func IsWindows() bool
|
func IsWindows() bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/zIflQgZNuxD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -64,7 +64,7 @@ func main() {
|
|||||||
|
|
||||||
<p>检查当前操作系统是否是linux</p>
|
<p>检查当前操作系统是否是linux</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/zIflQgZNuxD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func IsLinux() bool
|
func IsLinux() bool
|
||||||
@@ -94,7 +94,7 @@ func main() {
|
|||||||
func IsMac() bool
|
func IsMac() bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Mg4Hjtyq7Zc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -118,7 +118,7 @@ func main() {
|
|||||||
func GetOsEnv(key string) string
|
func GetOsEnv(key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/D88OYVCyjO-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -148,7 +148,7 @@ func main() {
|
|||||||
func SetOsEnv(key, value string) error
|
func SetOsEnv(key, value string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/D88OYVCyjO-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -178,7 +178,7 @@ func main() {
|
|||||||
func RemoveOsEnv(key string) error
|
func RemoveOsEnv(key string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/fqyq4b3xUFQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -216,7 +216,7 @@ func main() {
|
|||||||
func CompareOsEnv(key, comparedEnv string) bool
|
func CompareOsEnv(key, comparedEnv string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/BciHrKYOHbp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -252,7 +252,7 @@ type (
|
|||||||
func ExecCommand(command string, opts ...Option) (stdout, stderr string, err error)
|
func ExecCommand(command string, opts ...Option) (stdout, stderr string, err error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/n-2fLyZef-4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -292,7 +292,7 @@ func main() {
|
|||||||
func GetOsBits() int
|
func GetOsBits() int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ml-_XH3gJbW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -61,6 +61,7 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="Tuple2">Tuple2</span>
|
### <span id="Tuple2">Tuple2</span>
|
||||||
@@ -78,7 +79,7 @@ type Tuple2[A any, B any] struct {
|
|||||||
func NewTuple2[A any, B any](a A, b B) Tuple2[A, B]
|
func NewTuple2[A any, B any](a A, b B) Tuple2[A, B]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/3sHVqBQpLYN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -106,7 +107,7 @@ func main() {
|
|||||||
func (t Tuple2[A, B]) Unbox() (A, B)
|
func (t Tuple2[A, B]) Unbox() (A, B)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/0fD1qfCVwjm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -135,7 +136,7 @@ func main() {
|
|||||||
func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B]
|
func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/4ncWJJ77Xio)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -163,7 +164,7 @@ func main() {
|
|||||||
func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B)
|
func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/KBecr60feXb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -198,7 +199,7 @@ type Tuple3[A any, B any, C any] struct {
|
|||||||
func NewTuple3[A any, B any, C any](a A, b B c C) Tuple3[A, B, C]
|
func NewTuple3[A any, B any, C any](a A, b B c C) Tuple3[A, B, C]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/FtH2sdCLlCf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -226,7 +227,7 @@ func main() {
|
|||||||
func (t Tuple3[A, B, C]) Unbox() (A, B, C)
|
func (t Tuple3[A, B, C]) Unbox() (A, B, C)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/YojLy-id1BS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -255,7 +256,7 @@ func main() {
|
|||||||
func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C]
|
func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/97NgmsTILfu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -283,7 +284,7 @@ func main() {
|
|||||||
func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C)
|
func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/bba4cpAa7KO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -321,7 +322,7 @@ type Tuple4[A any, B any, C any, D any] struct {
|
|||||||
func NewTuple4[A any, B any, C any, D any](a A, b B, c C, d D) Tuple4[A, B, C, D]
|
func NewTuple4[A any, B any, C any, D any](a A, b B, c C, d D) Tuple4[A, B, C, D]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/D2EqDz096tk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -349,7 +350,7 @@ func main() {
|
|||||||
func (t Tuple4[A, B, C, D]) Unbox() (A, B, C, D)
|
func (t Tuple4[A, B, C, D]) Unbox() (A, B, C, D)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ACj9YuACGgW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -378,7 +379,7 @@ func main() {
|
|||||||
func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D]
|
func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/PEmTYVK5hL4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -406,7 +407,7 @@ func main() {
|
|||||||
func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D)
|
func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/rb8z4gyYSRN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -445,7 +446,7 @@ type Tuple5[A any, B any, C any, D any, E any] struct {
|
|||||||
func NewTuple5[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E) Tuple5[A, B, C, D, E]
|
func NewTuple5[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E) Tuple5[A, B, C, D, E]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/2WndmVxPg-r)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -473,7 +474,7 @@ func main() {
|
|||||||
func (t Tuple5[A, B, C, D, E]) Unbox() (A, B, C, D, E)
|
func (t Tuple5[A, B, C, D, E]) Unbox() (A, B, C, D, E)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/GyIyZHjCvoS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -502,7 +503,7 @@ func main() {
|
|||||||
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E]
|
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/fCAAJLMfBIP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -530,7 +531,7 @@ func main() {
|
|||||||
func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E)
|
func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/gyl6vKfhqPb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -570,7 +571,7 @@ type Tuple6[A any, B any, C any, D any, E any, F any] struct {
|
|||||||
func NewTuple6[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F]
|
func NewTuple6[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/VjqcCwEJZbs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -598,7 +599,7 @@ func main() {
|
|||||||
func (t Tuple6[A, B, C, D, E, F]) Unbox() (A, B, C, D, E, F)
|
func (t Tuple6[A, B, C, D, E, F]) Unbox() (A, B, C, D, E, F)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/FjIHV7lpxmW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -627,7 +628,7 @@ func main() {
|
|||||||
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F]
|
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/oWPrnUYuFHo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -655,7 +656,7 @@ func main() {
|
|||||||
func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F)
|
func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/l41XFqCyh5E)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -696,7 +697,7 @@ type Tuple7[A any, B any, C any, D any, E any, F any, G any] struct {
|
|||||||
func NewTuple7[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G]
|
func NewTuple7[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/dzAgv_Ezub9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -724,7 +725,7 @@ func main() {
|
|||||||
func (t Tuple7[A, B, C, D, E, F, G]) Unbox() (A, B, C, D, E, F, G)
|
func (t Tuple7[A, B, C, D, E, F, G]) Unbox() (A, B, C, D, E, F, G)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/R9I8qeDk0zs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -753,7 +754,7 @@ func main() {
|
|||||||
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G]
|
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/WUJuo897Egf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -781,7 +782,7 @@ func main() {
|
|||||||
func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G)
|
func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/hws_P1Fr2j3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -823,7 +824,7 @@ type Tuple8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
|
|||||||
func NewTuple8[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H]
|
func NewTuple8[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/YA9S0rz3dRz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -851,7 +852,7 @@ func main() {
|
|||||||
func (t Tuple8[A, B, C, D, E, F, G, H]) Unbox() (A, B, C, D, E, F, G, H)
|
func (t Tuple8[A, B, C, D, E, F, G, H]) Unbox() (A, B, C, D, E, F, G, H)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/PRxLBBb4SMl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -880,7 +881,7 @@ func main() {
|
|||||||
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H]
|
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/8V9jWkuJfaQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -908,7 +909,7 @@ func main() {
|
|||||||
func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H)
|
func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/1SndOwGsZB4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -953,7 +954,7 @@ func NewTuple9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/yS2NGGtZpQr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -981,7 +982,7 @@ func main() {
|
|||||||
func (t Tuple9[A, B, C, D, E, F, G, H, I]) Unbox() (A, B, C, D, E, F, G, H, I)
|
func (t Tuple9[A, B, C, D, E, F, G, H, I]) Unbox() (A, B, C, D, E, F, G, H, I)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/oFJFGTAuOa8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1010,7 +1011,7 @@ func main() {
|
|||||||
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I]
|
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/cgsL15QYnfz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1038,7 +1039,7 @@ func main() {
|
|||||||
func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I)
|
func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/91-BU_KURSA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1084,7 +1085,7 @@ func NewTuple10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/799qqZg0hUv)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1115,7 +1116,7 @@ func main() {
|
|||||||
func (t Tuple10[A, B, C, D, E, F, G, H, I, J]) Unbox() (A, B, C, D, E, F, G, H, I, J)
|
func (t Tuple10[A, B, C, D, E, F, G, H, I, J]) Unbox() (A, B, C, D, E, F, G, H, I, J)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/qfyx3x_X0Cu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1147,7 +1148,7 @@ func main() {
|
|||||||
func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I, j []J) []Tuple10[A, B, C, D, E, F, G, H, I, J]
|
func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I, j []J) []Tuple10[A, B, C, D, E, F, G, H, I, J]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/YSR-2cXnrY4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1175,7 +1176,7 @@ func main() {
|
|||||||
func Unzip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](tuples []Tuple10[A, B, C, D, E, F, G, H, I, J]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I, []J)
|
func Unzip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](tuples []Tuple10[A, B, C, D, E, F, G, H, I, J]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I, []J)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/-taQB6Wfre_z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -55,6 +55,15 @@ import (
|
|||||||
- [IsZeroValue](#IsZeroValue)
|
- [IsZeroValue](#IsZeroValue)
|
||||||
- [IsGBK](#IsGBK)
|
- [IsGBK](#IsGBK)
|
||||||
- [IsPrintable](#IsPrintable)
|
- [IsPrintable](#IsPrintable)
|
||||||
|
- [IsBin](#IsBin)
|
||||||
|
- [IsHex](#IsHex)
|
||||||
|
- [IsBase64URL](#IsBase64URL)
|
||||||
|
- [IsJWT](#IsJWT)
|
||||||
|
- [IsVisa](#IsVisa)
|
||||||
|
- [IsMasterCard](#IsMasterCard)
|
||||||
|
- [IsAmericanExpress](#IsAmericanExpress)
|
||||||
|
- [IsUnionPay](#IsUnionPay)
|
||||||
|
- [IsChinaUnionPay](#IsChinaUnionPay)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -62,7 +71,7 @@ import (
|
|||||||
|
|
||||||
### <span id="ContainChinese">ContainChinese</span>
|
### <span id="ContainChinese">ContainChinese</span>
|
||||||
|
|
||||||
<p>验证字符串是否包含中文字符</p>
|
<p>验证字符串是否包含中文字符。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -70,7 +79,7 @@ import (
|
|||||||
func ContainChinese(s string) bool
|
func ContainChinese(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/7DpU0uElYeM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -96,7 +105,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="ContainLetter">ContainLetter</span>
|
### <span id="ContainLetter">ContainLetter</span>
|
||||||
|
|
||||||
<p>验证字符串是否包含至少一个英文字母</p>
|
<p>验证字符串是否包含至少一个英文字母。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -104,7 +113,7 @@ func main() {
|
|||||||
func ContainLetter(str string) bool
|
func ContainLetter(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/lqFD04Yyewp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -130,7 +139,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="ContainLower">ContainLower</span>
|
### <span id="ContainLower">ContainLower</span>
|
||||||
|
|
||||||
<p>验证字符串是否包含至少一个英文小写字母</p>
|
<p>验证字符串是否包含至少一个英文小写字母。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -138,7 +147,7 @@ func main() {
|
|||||||
func ContainLower(str string) bool
|
func ContainLower(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Srqi1ItvnAA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -164,7 +173,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="ContainUpper">ContainUpper</span>
|
### <span id="ContainUpper">ContainUpper</span>
|
||||||
|
|
||||||
<p>验证字符串是否包含至少一个英文大写字母.</p>
|
<p>验证字符串是否包含至少一个英文大写字母。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -172,7 +181,7 @@ func main() {
|
|||||||
func ContainUpper(str string) bool
|
func ContainUpper(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/CmWeBEk27-z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -198,7 +207,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsAlpha">IsAlpha</span>
|
### <span id="IsAlpha">IsAlpha</span>
|
||||||
|
|
||||||
<p>验证字符串是否只包含英文字母</p>
|
<p>验证字符串是否只包含英文字母。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -206,7 +215,7 @@ func main() {
|
|||||||
func IsAlpha(s string) bool
|
func IsAlpha(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/7Q5sGOz2izQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -232,7 +241,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsAllUpper">IsAllUpper</span>
|
### <span id="IsAllUpper">IsAllUpper</span>
|
||||||
|
|
||||||
<p>验证字符串是否全是大写英文字母</p>
|
<p>验证字符串是否全是大写英文字母。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -240,7 +249,7 @@ func main() {
|
|||||||
func IsAllUpper(str string) bool
|
func IsAllUpper(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ZHctgeK1n4Z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -266,7 +275,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsAllLower">IsAllLower</span>
|
### <span id="IsAllLower">IsAllLower</span>
|
||||||
|
|
||||||
<p>验证字符串是否全是小写英文字母</p>
|
<p>验证字符串是否全是小写英文字母。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -274,7 +283,7 @@ func main() {
|
|||||||
func IsAllLower(str string) bool
|
func IsAllLower(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/GjqCnOfV6cM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -308,7 +317,7 @@ func main() {
|
|||||||
func IsASCII(str string) bool
|
func IsASCII(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/hfQNPLX0jNa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -340,7 +349,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsBase64">IsBase64</span>
|
### <span id="IsBase64">IsBase64</span>
|
||||||
|
|
||||||
<p>验证字符串是否是base64编码</p>
|
<p>验证字符串是否是base64编码。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -348,7 +357,7 @@ func main() {
|
|||||||
func IsBase64(base64 string) bool
|
func IsBase64(base64 string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/sWHEySAt6hl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -371,7 +380,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsChineseMobile">IsChineseMobile</span>
|
### <span id="IsChineseMobile">IsChineseMobile</span>
|
||||||
|
|
||||||
<p>验证字符串是否是中国手机号码</p>
|
<p>验证字符串是否是中国手机号码。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -379,7 +388,7 @@ func main() {
|
|||||||
func IsChineseMobile(mobileNum string) bool
|
func IsChineseMobile(mobileNum string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/GPYUlGTOqe3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -402,7 +411,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsChineseIdNum">IsChineseIdNum</span>
|
### <span id="IsChineseIdNum">IsChineseIdNum</span>
|
||||||
|
|
||||||
<p>验证字符串是否是中国身份证号码</p>
|
<p>验证字符串是否是中国身份证号码。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -410,7 +419,7 @@ func main() {
|
|||||||
func IsChineseIdNum(id string) bool
|
func IsChineseIdNum(id string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/d8EWhl2UGDF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -433,7 +442,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsChinesePhone">IsChinesePhone</span>
|
### <span id="IsChinesePhone">IsChinesePhone</span>
|
||||||
|
|
||||||
<p>验证字符串是否是中国电话座机号码</p>
|
<p>验证字符串是否是中国电话座机号码。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -441,7 +450,7 @@ func main() {
|
|||||||
func IsChinesePhone(phone string) bool
|
func IsChinesePhone(phone string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/RUD_-7YZJ3I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -464,7 +473,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsCreditCard">IsCreditCard</span>
|
### <span id="IsCreditCard">IsCreditCard</span>
|
||||||
|
|
||||||
<p>验证字符串是否是信用卡号码</p>
|
<p>验证字符串是否是信用卡号码。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -472,7 +481,7 @@ func main() {
|
|||||||
func IsCreditCard(creditCart string) bool
|
func IsCreditCard(creditCart string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/sNwwL6B0-v4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -495,7 +504,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsDns">IsDns</span>
|
### <span id="IsDns">IsDns</span>
|
||||||
|
|
||||||
<p>验证字符串是否是有效dns</p>
|
<p>验证字符串是否是有效dns。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -503,7 +512,7 @@ func main() {
|
|||||||
func IsDns(dns string) bool
|
func IsDns(dns string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/jlYApVLLGTZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -529,7 +538,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsEmail">IsEmail</span>
|
### <span id="IsEmail">IsEmail</span>
|
||||||
|
|
||||||
<p>验证字符串是否是有效电子邮件地址</p>
|
<p>验证字符串是否是有效电子邮件地址。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -537,7 +546,7 @@ func main() {
|
|||||||
func IsEmail(email string) bool
|
func IsEmail(email string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Os9VaFlT33G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -560,7 +569,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsEmptyString">IsEmptyString</span>
|
### <span id="IsEmptyString">IsEmptyString</span>
|
||||||
|
|
||||||
<p>验证字符串是否是空字符串</p>
|
<p>验证字符串是否是空字符串。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -568,7 +577,7 @@ func main() {
|
|||||||
func IsEmptyString(s string) bool
|
func IsEmptyString(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/dpzgUjFnBCX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -602,7 +611,7 @@ func main() {
|
|||||||
func IsInt(v any) bool
|
func IsInt(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/eFoIHbgzl-z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -631,7 +640,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsFloat">IsFloat</span>
|
### <span id="IsFloat">IsFloat</span>
|
||||||
|
|
||||||
<p>验证参数是否是浮点数((float32, float34)。</p>
|
<p>验证参数是否是浮点数(float32, float34)。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -639,7 +648,7 @@ func main() {
|
|||||||
func IsFloat(v any) bool
|
func IsFloat(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/vsyG-sxr99_Z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -668,7 +677,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsNumber">IsNumber</span>
|
### <span id="IsNumber">IsNumber</span>
|
||||||
|
|
||||||
<p>验证参数是否是数字(integer or float)</p>
|
<p>验证参数是否是数字(integer or float)。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -676,7 +685,7 @@ func main() {
|
|||||||
func IsNumber(v any) bool
|
func IsNumber(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/mdJHOAvtsvF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -703,10 +712,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="IsIntStr">IsIntStr</span>
|
### <span id="IsIntStr">IsIntStr</span>
|
||||||
|
|
||||||
<p>验证字符串是否是可以转换为整数</p>
|
<p>验证字符串是否是可以转换为整数。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -714,7 +722,7 @@ func main() {
|
|||||||
func IsIntStr(s string) bool
|
func IsIntStr(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/jQRtFv-a0Rk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -743,7 +751,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsFloatStr">IsFloatStr</span>
|
### <span id="IsFloatStr">IsFloatStr</span>
|
||||||
|
|
||||||
<p>验证字符串是否是可以转换为浮点数</p>
|
<p>验证字符串是否是可以转换为浮点数。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -751,7 +759,7 @@ func main() {
|
|||||||
func IsFloatStr(s string) bool
|
func IsFloatStr(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/LOYwS_Oyl7U)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -780,7 +788,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsNumberStr">IsNumberStr</span>
|
### <span id="IsNumberStr">IsNumberStr</span>
|
||||||
|
|
||||||
<p>验证字符串是否是可以转换为数字</p>
|
<p>验证字符串是否是可以转换为数字。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -788,7 +796,7 @@ func main() {
|
|||||||
func IsNumberStr(s string) bool
|
func IsNumberStr(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/LzaKocSV79u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -817,7 +825,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsJSON">IsJSON</span>
|
### <span id="IsJSON">IsJSON</span>
|
||||||
|
|
||||||
<p>验证字符串是否是有效json</p>
|
<p>验证字符串是否是有效json。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -825,7 +833,7 @@ func main() {
|
|||||||
func IsJSON(str string) bool
|
func IsJSON(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/8Kip1Itjiil)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -854,7 +862,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsRegexMatch">IsRegexMatch</span>
|
### <span id="IsRegexMatch">IsRegexMatch</span>
|
||||||
|
|
||||||
<p>验证字符串是否可以匹配正则表达式</p>
|
<p>验证字符串是否可以匹配正则表达式。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -862,7 +870,7 @@ func main() {
|
|||||||
func IsRegexMatch(s, regex string) bool
|
func IsRegexMatch(s, regex string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/z_XeZo_litG)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -883,11 +891,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="IsIp">IsIp</span>
|
### <span id="IsIp">IsIp</span>
|
||||||
|
|
||||||
<p>验证字符串是否是ip地址</p>
|
<p>验证字符串是否是ip地址。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -895,7 +901,7 @@ func main() {
|
|||||||
func IsIp(ipstr string) bool
|
func IsIp(ipstr string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/FgcplDvmxoD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -924,7 +930,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsIpV4">IsIpV4</span>
|
### <span id="IsIpV4">IsIpV4</span>
|
||||||
|
|
||||||
<p>验证字符串是否是ipv4地址</p>
|
<p>验证字符串是否是ipv4地址。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -932,7 +938,7 @@ func main() {
|
|||||||
func IsIpV4(ipstr string) bool
|
func IsIpV4(ipstr string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/zBGT99EjaIu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -955,7 +961,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsIpV6">IsIpV6</span>
|
### <span id="IsIpV6">IsIpV6</span>
|
||||||
|
|
||||||
<p>验证字符串是否是ipv6地址</p>
|
<p>验证字符串是否是ipv6地址。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -963,7 +969,7 @@ func main() {
|
|||||||
func IsIpV6(ipstr string) bool
|
func IsIpV6(ipstr string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/AHA0r0AzIdC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -986,7 +992,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsStrongPassword">IsStrongPassword</span>
|
### <span id="IsStrongPassword">IsStrongPassword</span>
|
||||||
|
|
||||||
<p>验证字符串是否是强密码:(alpha(lower+upper) + number + special chars(!@#$%^&*()?><))</p>
|
<p>验证字符串是否是强密码:(alpha(lower+upper) + number + special chars(!@#$%^&*()?><))。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -994,7 +1000,7 @@ func main() {
|
|||||||
func IsStrongPassword(password string, length int) bool
|
func IsStrongPassword(password string, length int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/QHdVcSQ3uDg)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1017,7 +1023,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsUrl">IsUrl</span>
|
### <span id="IsUrl">IsUrl</span>
|
||||||
|
|
||||||
<p>验证字符串是否是url</p>
|
<p>验证字符串是否是url。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -1025,7 +1031,7 @@ func main() {
|
|||||||
func IsUrl(str string) bool
|
func IsUrl(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/pbJGa7F98Ka)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1052,7 +1058,7 @@ func main() {
|
|||||||
### <span id="IsWeakPassword">IsWeakPassword</span>
|
### <span id="IsWeakPassword">IsWeakPassword</span>
|
||||||
|
|
||||||
<p>验证字符串是否是弱密码:(only letter or only number or letter + number)
|
<p>验证字符串是否是弱密码:(only letter or only number or letter + number)
|
||||||
.</p>
|
。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -1060,7 +1066,7 @@ func main() {
|
|||||||
func IsWeakPassword(password string, length int) bool
|
func IsWeakPassword(password string, length int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/wqakscZH5gH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1083,7 +1089,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsZeroValue">IsZeroValue</span>
|
### <span id="IsZeroValue">IsZeroValue</span>
|
||||||
|
|
||||||
<p>判断传入的参数值是否为零值</p>
|
<p>判断传入的参数值是否为零值。</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
@@ -1091,7 +1097,7 @@ func main() {
|
|||||||
func IsZeroValue(value any) bool
|
func IsZeroValue(value any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/UMrwaDCi_t4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1128,7 +1134,7 @@ func main() {
|
|||||||
func IsGBK(data []byte) bool
|
func IsGBK(data []byte) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/E2nt3unlmzP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1150,7 +1156,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="IsPrintable">IsPrintable</span>
|
### <span id="IsPrintable">IsPrintable</span>
|
||||||
|
|
||||||
<p>检查字符串是否全部为可打印字符。</p>
|
<p>检查字符串是否全部为可打印字符。</p>
|
||||||
@@ -1161,7 +1166,7 @@ func main() {
|
|||||||
func IsPrintable(str string) bool
|
func IsPrintable(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Pe1FE2gdtTP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1189,4 +1194,301 @@ func main() {
|
|||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="IsBin">IsBin</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的二进制数。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsBin(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ogPeg2XJH4P)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsBin("0101")
|
||||||
|
result2 := validator.IsBin("0b1101")
|
||||||
|
result3 := validator.IsBin("b1101")
|
||||||
|
result4 := validator.IsBin("1201")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsHex">IsHex</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的十六进制数。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsHex(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/M2qpHbEwmm7)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsHex("0xabcde")
|
||||||
|
result2 := validator.IsHex("0XABCDE")
|
||||||
|
result3 := validator.IsHex("cdfeg")
|
||||||
|
result4 := validator.IsHex("0xcdfeg")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsBase64URL">IsBase64URL</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的base64 url。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsBase64URL(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/vhl4mr8GZ6S)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ")
|
||||||
|
result2 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ==")
|
||||||
|
result3 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ=")
|
||||||
|
result4 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ===")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsJWT">IsJWT</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的JSON Web Token (JWT)。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsJWT(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/R6Op7heJbKI)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibWVzc2FnZSI6IlB1dGluIGlzIGFic29sdXRlIHNoaXQiLCJpYXQiOjE1MTYyMzkwMjJ9.wkLWA5GtCpWdxNOrRse8yHZgORDgf8TpJp73WUQb910")
|
||||||
|
result2 := validator.IsJWT("abc")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsVisa">IsVisa</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的visa卡号。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsVisa(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/SdS2keOyJsl)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsVisa("4111111111111111")
|
||||||
|
result2 := validator.IsVisa("123")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsMasterCard">IsMasterCard</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的MasterCard卡号。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsMasterCard(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/CwWBFRrG27b)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsMasterCard("5425233430109903")
|
||||||
|
result2 := validator.IsMasterCard("4111111111111111")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsAmericanExpress">IsAmericanExpress</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的American Express卡号。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsAmericanExpress(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/HIDFpcOdpkd)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsAmericanExpress("342883359122187")
|
||||||
|
result2 := validator.IsAmericanExpress("3782822463100007")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsUnionPay">IsUnionPay</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的美国银联卡号。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsUnionPay(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/CUHPEwEITDf)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsUnionPay("6221263430109903")
|
||||||
|
result2 := validator.IsUnionPay("3782822463100007")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsChinaUnionPay">IsChinaUnionPay</span>
|
||||||
|
|
||||||
|
<p>检查字符串是否是有效的中国银联卡号。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsChinaUnionPay(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/yafpdxLiymu)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsChinaUnionPay("6250941006528599")
|
||||||
|
result2 := validator.IsChinaUnionPay("3782822463100007")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -38,6 +38,7 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
### <span id="New">New</span>
|
### <span id="New">New</span>
|
||||||
@@ -58,7 +59,7 @@ type XError struct {
|
|||||||
func New(format string, args ...any) *XError
|
func New(format string, args ...any) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/w4oWZts7q7f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -87,7 +88,7 @@ func main() {
|
|||||||
func Wrap(cause error, message ...any) *XError
|
func Wrap(cause error, message ...any) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/5385qT2dCi4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -118,7 +119,7 @@ func main() {
|
|||||||
func Unwrap(err error) *XError
|
func Unwrap(err error) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/LKMLep723tu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -153,24 +154,25 @@ func main() {
|
|||||||
func (e *XError) Wrap(cause error) *XError
|
func (e *XError) Wrap(cause error) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/RpjJ5u5sc97)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"errors"
|
||||||
"github.com/duke-git/lancet/v2/xerror"
|
"github.com/duke-git/lancet/v2/xerror"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := xerror.New("wrong password")
|
err1 := xerror.New("error").With("level", "high")
|
||||||
wrapErr := xerror.Wrap(err, "error")
|
err2 := err1.Wrap(errors.New("invalid username"))
|
||||||
|
|
||||||
fmt.Println(wrapErr.Error())
|
fmt.Println(err2.Error())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// error: wrong password
|
// error: invalid username
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -184,7 +186,7 @@ func main() {
|
|||||||
func (e *XError) Unwrap() error
|
func (e *XError) Unwrap() error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/VUXJ8BST4c6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -217,7 +219,7 @@ func main() {
|
|||||||
func (e *XError) With(key string, value any) *XError
|
func (e *XError) With(key string, value any) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ow8UISXX_Dp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -249,7 +251,7 @@ func main() {
|
|||||||
func (e *XError) Id(id string) *XError
|
func (e *XError) Id(id string) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/X6HBlsy58U9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -286,7 +288,7 @@ func main() {
|
|||||||
func (e *XError) Is(target error) bool
|
func (e *XError) Is(target error) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/X6HBlsy58U9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -323,7 +325,7 @@ func main() {
|
|||||||
func (e *XError) Values() map[string]any
|
func (e *XError) Values() map[string]any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ow8UISXX_Dp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -356,7 +358,7 @@ func main() {
|
|||||||
func (e *XError) StackTrace() StackTrace
|
func (e *XError) StackTrace() StackTrace
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/6FAvSQpa7pc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -390,7 +392,7 @@ func main() {
|
|||||||
func (e *XError) Info() *errInfo
|
func (e *XError) Info() *errInfo
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/1ZX0ME1F-Jb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -430,7 +432,7 @@ func main() {
|
|||||||
func (e *XError) Error() string
|
func (e *XError) Error() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/w4oWZts7q7f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -459,7 +461,7 @@ func main() {
|
|||||||
func TryUnwrap[T any](val T, err error) T
|
func TryUnwrap[T any](val T, err error) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:</b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/acyZVkNZEeW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -27,7 +27,7 @@ outline: deep
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
background: #ecefff;
|
background: #059669;
|
||||||
border: 1px solid;
|
border: 1px solid;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
@@ -37,7 +37,7 @@ outline: deep
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p class="package-title">lancet function module</p>
|
<p class="package-title">Lancet function module</p>
|
||||||
<div class="package-container">
|
<div class="package-container">
|
||||||
<div class="package-cell">algorithm</div>
|
<div class="package-cell">algorithm</div>
|
||||||
<div class="package-cell">compare</div>
|
<div class="package-cell">compare</div>
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ Package algorithm implements some basic algorithm. eg. sort, search.
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```go
|
```go
|
||||||
@@ -53,7 +51,7 @@ import (
|
|||||||
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/GNdv7Jg2Taj)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/GNdv7Jg2Taj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -101,7 +99,7 @@ func main() {
|
|||||||
func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/G5LJiWgJJW6)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/G5LJiWgJJW6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -164,7 +162,7 @@ func main() {
|
|||||||
func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/oXovbkekayS)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/oXovbkekayS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -212,7 +210,7 @@ func main() {
|
|||||||
func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/3ibkszpJEu3)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/3ibkszpJEu3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -260,7 +258,7 @@ func main() {
|
|||||||
func QuickSort[T any](slice []T comparator lancetconstraints.Comparator)
|
func QuickSort[T any](slice []T comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/7Y7c1Elk3ax)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/7Y7c1Elk3ax)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -308,7 +306,7 @@ func main() {
|
|||||||
func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/u6Iwa1VZS_f)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/u6Iwa1VZS_f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -356,7 +354,7 @@ func main() {
|
|||||||
func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/ydinn9YzUJn)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ydinn9YzUJn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -404,7 +402,7 @@ func main() {
|
|||||||
func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
|
func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/tB-Umgm0DrP)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tB-Umgm0DrP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -453,7 +451,7 @@ func main() {
|
|||||||
func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/t6MeGiUSN47)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/t6MeGiUSN47)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -504,7 +502,7 @@ func main() {
|
|||||||
func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/Anozfr8ZLH3)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Anozfr8ZLH3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -555,7 +553,7 @@ func main() {
|
|||||||
func LinearSearch[T any](slice []T, target T, equal func(a, b T) bool) int
|
func LinearSearch[T any](slice []T, target T, equal func(a, b T) bool) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/IsS7rgn5s3x)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/IsS7rgn5s3x)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -598,7 +596,7 @@ func (l *LRUCache[K, V]) Delete(key K) bool
|
|||||||
func (l *LRUCache[K, V]) Len() int
|
func (l *LRUCache[K, V]) Len() int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/IsS7rgn5s3x)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/IsS7rgn5s3x)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -34,15 +34,13 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="Equal">Equal</span>
|
### <span id="Equal">Equal</span>
|
||||||
|
|
||||||
<p>Checks if two values are equal or not. (check both type and value)</p>
|
<p>Checks if two values are equal or not. (check both type and value)</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/wmVxR-to4lz)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/wmVxR-to4lz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Equal(left, right any) bool
|
func Equal(left, right any) bool
|
||||||
@@ -91,7 +89,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Checks if two values are equal or not. (check value only)</p>
|
<p>Checks if two values are equal or not. (check value only)</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/fxnna_LLD9u)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fxnna_LLD9u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func EqualValue(left, right any) bool
|
func EqualValue(left, right any) bool
|
||||||
@@ -130,7 +128,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Checks if value `left` less than value `right`.</p>
|
<p>Checks if value `left` less than value `right`.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/cYh7FQQj0ne)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/cYh7FQQj0ne)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func LessThan(left, right any) bool
|
func LessThan(left, right any) bool
|
||||||
@@ -185,7 +183,7 @@ func main() {
|
|||||||
func GreaterThan(left, right any) bool
|
func GreaterThan(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/9-NYDFZmIMp)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9-NYDFZmIMp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -237,7 +235,7 @@ func main() {
|
|||||||
func LessOrEqual(left, right any) bool
|
func LessOrEqual(left, right any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/e4T_scwoQzp)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/e4T_scwoQzp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -280,7 +278,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Checks if value `left` less greater or equal than value `right`.</p>
|
<p>Checks if value `left` less greater or equal than value `right`.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/vx8mP0U8DFk)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/vx8mP0U8DFk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func GreaterOrEqual(left, right any) bool
|
func GreaterOrEqual(left, right any) bool
|
||||||
@@ -332,7 +330,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Checks if two values are equal or not within a delta.</p>
|
<p>Checks if two values are equal or not within a delta.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/TuDdcNtMkjo)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/TuDdcNtMkjo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func InDelta[T constraints.Integer | constraints.Float](left, right T, delta float64) bool
|
func InDelta[T constraints.Integer | constraints.Float](left, right T, delta float64) bool
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
## Channel
|
## Channel
|
||||||
@@ -47,7 +45,7 @@ import (
|
|||||||
type Channel[T any] struct
|
type Channel[T any] struct
|
||||||
func NewChannel[T any]() *Channel[T]
|
func NewChannel[T any]() *Channel[T]
|
||||||
```
|
```
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -71,7 +69,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Bridge(ctx context.Context, chanStream <-chan <-chan T) <-chan T
|
func (c *Channel[T]) Bridge(ctx context.Context, chanStream <-chan <-chan T) <-chan T
|
||||||
```
|
```
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/qmWSy1NVF-Y)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qmWSy1NVF-Y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -123,7 +121,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) FanIn(ctx context.Context, channels ...<-chan T) <-chan T
|
func (c *Channel[T]) FanIn(ctx context.Context, channels ...<-chan T) <-chan T
|
||||||
```
|
```
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/2VYFMexEvTm)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/2VYFMexEvTm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -157,7 +155,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Create channel, put values into the channel repeatly until cancel the context.</p>
|
<p>Create channel, put values into the channel repeatly until cancel the context.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/k5N_ALVmYjE)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/k5N_ALVmYjE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Repeat(ctx context.Context, values ...T) <-chan T
|
func (c *Channel[T]) Repeat(ctx context.Context, values ...T) <-chan T
|
||||||
@@ -201,7 +199,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Generate(ctx context.Context, values ...T) <-chan T
|
func (c *Channel[T]) Generate(ctx context.Context, values ...T) <-chan T
|
||||||
```
|
```
|
||||||
<b>Example: <span class="run-container">[Run](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
<b>Example: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/7aB4KyMMp9A)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -234,7 +232,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Create a channel, excutes fn repeatly, and put the result into the channel, until close context.</p>
|
<p>Create a channel, excutes fn repeatly, and put the result into the channel, until close context.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/4J1zAWttP85)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4J1zAWttP85)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *Channel[T]) RepeatFn(ctx context.Context, fn func() T) <-chan T
|
func (c *Channel[T]) RepeatFn(ctx context.Context, fn func() T) <-chan T
|
||||||
@@ -276,7 +274,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Read one or more channels into one channel, will close when any readin channel is closed.</p>
|
<p>Read one or more channels into one channel, will close when any readin channel is closed.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/Wqz9rwioPww)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Wqz9rwioPww)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Or(channels ...<-chan T) <-chan T
|
func (c *Channel[T]) Or(channels ...<-chan T) <-chan T
|
||||||
@@ -319,7 +317,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Read a channel into another channel, will close until cancel context.</p>
|
<p>Read a channel into another channel, will close until cancel context.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/lm_GoS6aDjo)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/lm_GoS6aDjo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *Channel[T]) OrDone(ctx context.Context, channel <-chan T) <-chan T
|
func (c *Channel[T]) OrDone(ctx context.Context, channel <-chan T) <-chan T
|
||||||
@@ -357,7 +355,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Create a channel whose values are taken from another channel with limit number.</p>
|
<p>Create a channel whose values are taken from another channel with limit number.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/9Utt-1pDr2J)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9Utt-1pDr2J)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Take(ctx context.Context, valueStream <-chan T, number int) <-chan T
|
func (c *Channel[T]) Take(ctx context.Context, valueStream <-chan T, number int) <-chan T
|
||||||
@@ -403,7 +401,7 @@ func main() {
|
|||||||
|
|
||||||
<p>Split one chanel into two channels, until cancel the context.</p>
|
<p>Split one chanel into two channels, until cancel the context.</p>
|
||||||
|
|
||||||
<b>Signature: <span class="run-container">[Run](https://go.dev/play/p/3TQPKnCirrP)</span></b>
|
<b>Signature: <span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/3TQPKnCirrP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *Channel[T]) Tee(ctx context.Context, in <-chan T) (<-chan T, <-chan T)
|
func (c *Channel[T]) Tee(ctx context.Context, in <-chan T) (<-chan T, <-chan T)
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +46,7 @@ All other types are truthy if they are not their zero value.</p>
|
|||||||
```go
|
```go
|
||||||
func Bool[T any](value T) bool
|
func Bool[T any](value T) bool
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/ETzeDJRSvhm)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ETzeDJRSvhm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -113,7 +111,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func And[T, U any](a T, b U) bool
|
func And[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/W1SSUmt6pvr)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/W1SSUmt6pvr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -141,7 +139,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Or[T, U any](a T, b U) bool
|
func Or[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/UlQTxHaeEkq)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/UlQTxHaeEkq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -169,7 +167,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Xor[T, U any](a T, b U) bool
|
func Xor[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/gObZrW7ZbG8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/gObZrW7ZbG8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -197,7 +195,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Nor[T, U any](a T, b U) bool
|
func Nor[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/g2j08F_zZky)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/g2j08F_zZky)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -224,7 +222,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Xnor[T, U any](a T, b U) bool
|
func Xnor[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/OuDB9g51643)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/OuDB9g51643)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -251,7 +249,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Nand[T, U any](a T, b U) bool
|
func Nand[T, U any](a T, b U) bool
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/vSRMLxLIbq8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/vSRMLxLIbq8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -279,7 +277,7 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U
|
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[运行](https://go.dev/play/p/ElllPZY0guT)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ElllPZY0guT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="ColorHexToRGB">ColorHexToRGB</span>
|
### <span id="ColorHexToRGB">ColorHexToRGB</span>
|
||||||
@@ -60,7 +58,7 @@ import (
|
|||||||
func ColorHexToRGB(colorHex string) (red, green, blue int)
|
func ColorHexToRGB(colorHex string) (red, green, blue int)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/o7_ft-JCJBV)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/o7_ft-JCJBV)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -91,7 +89,7 @@ func main() {
|
|||||||
func ColorRGBToHex(red, green, blue int) string
|
func ColorRGBToHex(red, green, blue int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nzKS2Ro87J1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nzKS2Ro87J1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -124,7 +122,7 @@ func main() {
|
|||||||
func ToBool(s string) (bool, error)
|
func ToBool(s string) (bool, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ARht2WnGdIN)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ARht2WnGdIN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -165,7 +163,7 @@ func main() {
|
|||||||
func ToBytes(data any) ([]byte, error)
|
func ToBytes(data any) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/fAMXYFDvOvr)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fAMXYFDvOvr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -198,7 +196,7 @@ func main() {
|
|||||||
func ToChar(s string) []string
|
func ToChar(s string) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/JJ1SvbFkVdM)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/JJ1SvbFkVdM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -234,7 +232,7 @@ func main() {
|
|||||||
func ToChannel[T any](array []T) <-chan T
|
func ToChannel[T any](array []T) <-chan T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/hOx_oYZbAnL)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/hOx_oYZbAnL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -271,7 +269,7 @@ func main() {
|
|||||||
func ToFloat(value any) (float64, error)
|
func ToFloat(value any) (float64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/4YTmPCibqHJ)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4YTmPCibqHJ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -316,7 +314,7 @@ func main() {
|
|||||||
func ToInt(value any) (int64, error)
|
func ToInt(value any) (int64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/9_h9vIt-QZ_b)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9_h9vIt-QZ_b)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -358,7 +356,7 @@ func main() {
|
|||||||
func ToJson(value any) (string, error)
|
func ToJson(value any) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/2rLIkMmXWvR)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/2rLIkMmXWvR)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -393,7 +391,7 @@ func main() {
|
|||||||
func ToMap[T any, K comparable, V any](array []T, iteratee func(T) (K, V)) map[K]V
|
func ToMap[T any, K comparable, V any](array []T, iteratee func(T) (K, V)) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/tVFy7E-t24l)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tVFy7E-t24l)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -434,7 +432,7 @@ func main() {
|
|||||||
func ToPointer[T any](value T) *T
|
func ToPointer[T any](value T) *T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ASf_etHNlw1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ASf_etHNlw1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -463,7 +461,7 @@ func main() {
|
|||||||
func ToString(value any) string
|
func ToString(value any) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nF1zOOslpQq)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nF1zOOslpQq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -511,7 +509,7 @@ func main() {
|
|||||||
func StructToMap(value any) (map[string]any, error)
|
func StructToMap(value any) (map[string]any, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/KYGYJqNUBOI)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KYGYJqNUBOI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -549,7 +547,7 @@ func main() {
|
|||||||
func MapToSlice[T any, K comparable, V any](aMap map[K]V, iteratee func(K, V) T) []T
|
func MapToSlice[T any, K comparable, V any](aMap map[K]V, iteratee func(K, V) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/dmX4Ix5V6Wl)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/dmX4Ix5V6Wl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -579,7 +577,7 @@ func main() {
|
|||||||
func EncodeByte(data any) ([]byte, error)
|
func EncodeByte(data any) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/DVmM1G5JfuP)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DVmM1G5JfuP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -608,7 +606,7 @@ func main() {
|
|||||||
func DecodeByte(data []byte, target any) error
|
func DecodeByte(data []byte, target any) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -644,7 +642,7 @@ func main() {
|
|||||||
func DeepClone[T any](src T) T
|
func DeepClone[T any](src T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/j4DP5dquxnk)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/j4DP5dquxnk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -708,7 +706,7 @@ func main() {
|
|||||||
func CopyProperties[T, U any](dst T, src U) (err error)
|
func CopyProperties[T, U any](dst T, src U) (err error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/oZujoB5Sgg5)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/oZujoB5Sgg5)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -787,7 +785,7 @@ func main() {
|
|||||||
func ToInterface(v reflect.Value) (value interface{}, ok bool)
|
func ToInterface(v reflect.Value) (value interface{}, ok bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/syqw0-WG7Xd)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/syqw0-WG7Xd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -822,7 +820,7 @@ func main() {
|
|||||||
func Utf8ToGbk(bs []byte) ([]byte, error)
|
func Utf8ToGbk(bs []byte) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/9FlIaFLArIL)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9FlIaFLArIL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -856,7 +854,7 @@ func main() {
|
|||||||
func GbkToUtf8(bs []byte) ([]byte, error)
|
func GbkToUtf8(bs []byte) ([]byte, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/OphmHCN_9u8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/OphmHCN_9u8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
# Cryptor
|
# Cryptor
|
||||||
|
|
||||||
Package cryptor contains some functions for data encryption and decryption. Support base64, md5, hmac, aes, des, rsa.
|
Package cryptor contains some functions for data encryption and decryption. Support base64, md5, hmac, aes, des, rsa.
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Source:
|
## Source:
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/cryptor/basic.go](https://github.com/duke-git/lancet/blob/main/cryptor/basic.go)
|
- [https://github.com/duke-git/lancet/blob/main/cryptor/basic.go](https://github.com/duke-git/lancet/blob/main/cryptor/basic.go)
|
||||||
- [https://github.com/duke-git/lancet/blob/main/cryptor/crypto.go](https://github.com/duke-git/lancet/blob/main/cryptor/crypto.go)
|
- [https://github.com/duke-git/lancet/blob/main/cryptor/crypto.go](https://github.com/duke-git/lancet/blob/main/cryptor/crypto.go)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Usage:
|
## Usage:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"github.com/duke-git/lancet/v2/cryptor"
|
"github.com/duke-git/lancet/v2/cryptor"
|
||||||
@@ -23,54 +23,54 @@ import (
|
|||||||
|
|
||||||
## Index
|
## Index
|
||||||
|
|
||||||
- [AesEcbEncrypt](#AesEcbEncrypt)
|
- [AesEcbEncrypt](#AesEcbEncrypt)
|
||||||
- [AesEcbDecrypt](#AesEcbDecrypt)
|
- [AesEcbDecrypt](#AesEcbDecrypt)
|
||||||
- [AesCbcEncrypt](#AesCbcEncrypt)
|
- [AesCbcEncrypt](#AesCbcEncrypt)
|
||||||
- [AesCbcDecrypt](#AesCbcDecrypt)
|
- [AesCbcDecrypt](#AesCbcDecrypt)
|
||||||
- [AesCtrCrypt](#AesCtrCrypt)
|
- [AesCtrCrypt](#AesCtrCrypt)
|
||||||
- [AesCfbEncrypt](#AesCfbEncrypt)
|
- [AesCfbEncrypt](#AesCfbEncrypt)
|
||||||
- [AesCfbDecrypt](#AesCfbDecrypt)
|
- [AesCfbDecrypt](#AesCfbDecrypt)
|
||||||
- [AesOfbEncrypt](#AesOfbEncrypt)
|
- [AesOfbEncrypt](#AesOfbEncrypt)
|
||||||
- [AesOfbDecrypt](#AesOfbDecrypt)
|
- [AesOfbDecrypt](#AesOfbDecrypt)
|
||||||
- [Base64StdEncode](#Base64StdEncode)
|
- [Base64StdEncode](#Base64StdEncode)
|
||||||
- [Base64StdDecode](#Base64StdDecode)
|
- [Base64StdDecode](#Base64StdDecode)
|
||||||
- [DesEcbEncrypt](#DesEcbEncrypt)
|
- [DesEcbEncrypt](#DesEcbEncrypt)
|
||||||
- [DesEcbDecrypt](#DesEcbDecrypt)
|
- [DesEcbDecrypt](#DesEcbDecrypt)
|
||||||
- [DesCbcEncrypt](#DesCbcEncrypt)
|
- [DesCbcEncrypt](#DesCbcEncrypt)
|
||||||
- [DesCbcDecrypt](#DesCbcDecrypt)
|
- [DesCbcDecrypt](#DesCbcDecrypt)
|
||||||
- [DesCtrCrypt](#DesCtrCrypt)
|
- [DesCtrCrypt](#DesCtrCrypt)
|
||||||
- [DesCfbEncrypt](#DesCfbEncrypt)
|
- [DesCfbEncrypt](#DesCfbEncrypt)
|
||||||
- [DesCfbDecrypt](#DesCfbDecrypt)
|
- [DesCfbDecrypt](#DesCfbDecrypt)
|
||||||
- [DesOfbEncrypt](#DesOfbEncrypt)
|
- [DesOfbEncrypt](#DesOfbEncrypt)
|
||||||
- [DesOfbDecrypt](#DesOfbDecrypt)
|
- [DesOfbDecrypt](#DesOfbDecrypt)
|
||||||
- [HmacMd5](#HmacMd5)
|
- [HmacMd5](#HmacMd5)
|
||||||
- [HmacMd5WithBase64](#HmacMd5WithBase64)
|
- [HmacMd5WithBase64](#HmacMd5WithBase64)
|
||||||
- [HmacSha1](#HmacSha1)
|
- [HmacSha1](#HmacSha1)
|
||||||
- [HmacSha1WithBase64](#HmacSha1WithBase64)
|
- [HmacSha1WithBase64](#HmacSha1WithBase64)
|
||||||
- [HmacSha256](#HmacSha256)
|
- [HmacSha256](#HmacSha256)
|
||||||
- [HmacSha256WithBase64](#HmacSha256WithBase64)
|
- [HmacSha256WithBase64](#HmacSha256WithBase64)
|
||||||
- [HmacSha512](#HmacSha512)
|
- [HmacSha512](#HmacSha512)
|
||||||
- [HmacSha512WithBase64](#HmacSha512WithBase64)
|
- [HmacSha512WithBase64](#HmacSha512WithBase64)
|
||||||
- [Md5String](#Md5String)
|
- [Md5String](#Md5String)
|
||||||
- [Md5StringWithBase64](#Md5StringWithBase64)
|
- [Md5StringWithBase64](#Md5StringWithBase64)
|
||||||
- [Md5Byte](#Md5Byte)
|
- [Md5Byte](#Md5Byte)
|
||||||
- [Md5ByteWithBase64](#Md5ByteWithBase64)
|
- [Md5ByteWithBase64](#Md5ByteWithBase64)
|
||||||
- [Md5File](#Md5File)
|
- [Md5File](#Md5File)
|
||||||
- [Sha1](#Sha1)
|
- [Sha1](#Sha1)
|
||||||
- [Sha1WithBase64](#Sha1WithBase64)
|
- [Sha1WithBase64](#Sha1WithBase64)
|
||||||
- [Sha256](#Sha256)
|
- [Sha256](#Sha256)
|
||||||
- [Sha256WithBase64](#Sha256WithBase64)
|
- [Sha256WithBase64](#Sha256WithBase64)
|
||||||
- [Sha512](#Sha512)
|
- [Sha512](#Sha512)
|
||||||
- [Sha512WithBase64](#Sha512WithBase64)
|
- [Sha512WithBase64](#Sha512WithBase64)
|
||||||
- [GenerateRsaKey](#GenerateRsaKey)
|
- [GenerateRsaKey](#GenerateRsaKey)
|
||||||
- [RsaEncrypt](#RsaEncrypt)
|
- [RsaEncrypt](#RsaEncrypt)
|
||||||
- [RsaDecrypt](#RsaDecrypt)
|
- [RsaDecrypt](#RsaDecrypt)
|
||||||
|
- [GenerateRsaKeyPair](#GenerateRsaKeyPair)
|
||||||
|
- [RsaEncryptOAEP](#RsaEncryptOAEP)
|
||||||
|
- [RsaDecryptOAEP](#RsaDecryptOAEP)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="AesEcbEncrypt">AesEcbEncrypt</span>
|
### <span id="AesEcbEncrypt">AesEcbEncrypt</span>
|
||||||
@@ -82,7 +82,8 @@ import (
|
|||||||
```go
|
```go
|
||||||
func AesEcbEncrypt(data, key []byte) []byte
|
func AesEcbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -115,7 +116,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func AesEcbDecrypt(encrypted, key []byte) []byte
|
func AesEcbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zI6xsmuQRbn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -148,7 +150,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func AesCbcEncrypt(data, key []byte) []byte
|
func AesCbcEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -182,7 +185,7 @@ func main() {
|
|||||||
func AesCbcDecrypt(encrypted, key []byte) []byte
|
func AesCbcDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/IOq_g8_lKZD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -216,7 +219,7 @@ func main() {
|
|||||||
func AesCtrCrypt(data, key []byte) []byte
|
func AesCtrCrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/SpaZO0-5Nsp)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/SpaZO0-5Nsp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -250,7 +253,7 @@ func main() {
|
|||||||
func AesCfbEncrypt(data, key []byte) []byte
|
func AesCfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -284,7 +287,7 @@ func main() {
|
|||||||
func AesCfbDecrypt(encrypted, key []byte) []byte
|
func AesCfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tfkF10B13kH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -318,7 +321,7 @@ func main() {
|
|||||||
func AesOfbEncrypt(data, key []byte) []byte
|
func AesOfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -341,6 +344,7 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="AesCfbDecrypt">AesOfbDecrypt</span>
|
### <span id="AesCfbDecrypt">AesOfbDecrypt</span>
|
||||||
|
|
||||||
<p>Decrypt data with key use AES OFB algorithm. Length of `key` param should be 16, 24 or 32.</p>
|
<p>Decrypt data with key use AES OFB algorithm. Length of `key` param should be 16, 24 or 32.</p>
|
||||||
@@ -351,7 +355,7 @@ func main() {
|
|||||||
func AesOfbDecrypt(encrypted, key []byte) []byte
|
func AesOfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VtHxtkUj-3F)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -384,7 +388,8 @@ func main() {
|
|||||||
```go
|
```go
|
||||||
func Base64StdEncode(s string) string
|
func Base64StdEncode(s string) string
|
||||||
```
|
```
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/VOaUyQUreoK)</span></b>
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VOaUyQUreoK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -402,6 +407,7 @@ func main() {
|
|||||||
// aGVsbG8=
|
// aGVsbG8=
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="Base64StdDecode">Base64StdDecode</span>
|
### <span id="Base64StdDecode">Base64StdDecode</span>
|
||||||
|
|
||||||
<p>Decode a base64 encoded string.</p>
|
<p>Decode a base64 encoded string.</p>
|
||||||
@@ -412,7 +418,7 @@ func main() {
|
|||||||
func Base64StdDecode(s string) string
|
func Base64StdDecode(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/RWQylnJVgIe)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/RWQylnJVgIe)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -441,7 +447,7 @@ func main() {
|
|||||||
func DesEcbEncrypt(data, key []byte) []byte
|
func DesEcbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -465,6 +471,7 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="DesEcbDecrypt">DesEcbDecrypt</span>
|
### <span id="DesEcbDecrypt">DesEcbDecrypt</span>
|
||||||
|
|
||||||
<p>Decrypt data with key use DES ECB algorithm. Length of `key` param should be 8.</p>
|
<p>Decrypt data with key use DES ECB algorithm. Length of `key` param should be 8.</p>
|
||||||
@@ -475,7 +482,7 @@ func main() {
|
|||||||
func DesEcbDecrypt(encrypted, key []byte) []byte
|
func DesEcbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/8qivmPeZy4P)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -510,7 +517,7 @@ func main() {
|
|||||||
func DesCbcEncrypt(data, key []byte) []byte
|
func DesCbcEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -544,7 +551,7 @@ func main() {
|
|||||||
func DesCbcDecrypt(encrypted, key []byte) []byte
|
func DesCbcDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4cC4QvWfe3_1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -567,6 +574,7 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="DesCtrCrypt">DesCtrCrypt</span>
|
### <span id="DesCtrCrypt">DesCtrCrypt</span>
|
||||||
|
|
||||||
<p>Encrypt or decrypt data with key use DES CTR algorithm. Length of `key` param should be 8.</p>
|
<p>Encrypt or decrypt data with key use DES CTR algorithm. Length of `key` param should be 8.</p>
|
||||||
@@ -577,7 +585,7 @@ func main() {
|
|||||||
func DesCtrCrypt(data, key []byte) []byte
|
func DesCtrCrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/9-T6OjKpcdw)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9-T6OjKpcdw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -611,7 +619,7 @@ func main() {
|
|||||||
func DesCfbEncrypt(data, key []byte) []byte
|
func DesCfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -634,6 +642,7 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="DesCfbDecrypt">DesCfbDecrypt</span>
|
### <span id="DesCfbDecrypt">DesCfbDecrypt</span>
|
||||||
|
|
||||||
<p>Decrypt data with key use DES CBC algorithm. Length of `key` param should be 8.</p>
|
<p>Decrypt data with key use DES CBC algorithm. Length of `key` param should be 8.</p>
|
||||||
@@ -644,7 +653,7 @@ func main() {
|
|||||||
func DesCfbDecrypt(encrypted, key []byte) []byte
|
func DesCfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/y-eNxcFBlxL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -667,6 +676,7 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="DesOfbEncrypt">DesOfbEncrypt</span>
|
### <span id="DesOfbEncrypt">DesOfbEncrypt</span>
|
||||||
|
|
||||||
<p>Enecrypt data with key use DES OFB algorithm. Length of `key` param should be 8.</p>
|
<p>Enecrypt data with key use DES OFB algorithm. Length of `key` param should be 8.</p>
|
||||||
@@ -677,7 +687,7 @@ func main() {
|
|||||||
func DesOfbEncrypt(data, key []byte) []byte
|
func DesOfbEncrypt(data, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -700,6 +710,7 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="DesOfbDecrypt">DesOfbDecrypt</span>
|
### <span id="DesOfbDecrypt">DesOfbDecrypt</span>
|
||||||
|
|
||||||
<p>Decrypt data with key use DES OFB algorithm. Length of `key` param should be 8.</p>
|
<p>Decrypt data with key use DES OFB algorithm. Length of `key` param should be 8.</p>
|
||||||
@@ -710,7 +721,7 @@ func main() {
|
|||||||
func DesOfbDecrypt(encrypted, key []byte) []byte
|
func DesOfbDecrypt(encrypted, key []byte) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/74KmNadjN1J)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -744,7 +755,7 @@ func main() {
|
|||||||
func HmacMd5(str, key string) string
|
func HmacMd5(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -776,7 +787,7 @@ func main() {
|
|||||||
func HmacMd5WithBase64(str, key string) string
|
func HmacMd5WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/UY0ng2AefFC)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/UY0ng2AefFC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -808,7 +819,7 @@ func main() {
|
|||||||
func HmacSha1(str, key string) string
|
func HmacSha1(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/1UI4oQ4WXKM)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1UI4oQ4WXKM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -840,7 +851,7 @@ func main() {
|
|||||||
func HmacSha1WithBase64(str, key string) string
|
func HmacSha1WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/47JmmGrnF7B)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/47JmmGrnF7B)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -872,7 +883,7 @@ func main() {
|
|||||||
func HmacSha256(str, key string) string
|
func HmacSha256(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/HhpwXxFhhC0)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/HhpwXxFhhC0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -904,7 +915,7 @@ func main() {
|
|||||||
func HmacSha256WithBase64(str, key string) string
|
func HmacSha256WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/EKbkUvPTLwO)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/EKbkUvPTLwO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -936,7 +947,7 @@ func main() {
|
|||||||
func HmacSha512(str, key string) string
|
func HmacSha512(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/59Od6m4A0Ud)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/59Od6m4A0Ud)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -968,7 +979,7 @@ func main() {
|
|||||||
func HmacSha512WithBase64(str, key string) string
|
func HmacSha512WithBase64(str, key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/c6dSe3E2ydU)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/c6dSe3E2ydU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -990,7 +1001,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="Md5String">Md5String</span>
|
### <span id="Md5String">Md5String</span>
|
||||||
|
|
||||||
<p>Get the md5 value of string.</p>
|
<p>Get the md5 value of string.</p>
|
||||||
@@ -1001,7 +1011,7 @@ func main() {
|
|||||||
func Md5String(s string) string
|
func Md5String(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/1bLcVetbTOI)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1bLcVetbTOI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1032,7 +1042,7 @@ func main() {
|
|||||||
func Md5StringWithBase64(s string) string
|
func Md5StringWithBase64(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Tcb-Z7LN2ax)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Tcb-Z7LN2ax)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1061,7 +1071,7 @@ func main() {
|
|||||||
func Md5Byte(data []byte) string
|
func Md5Byte(data []byte) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/suraalH8lyC)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/suraalH8lyC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1090,7 +1100,7 @@ func main() {
|
|||||||
func Md5ByteWithBase64(data []byte) string
|
func Md5ByteWithBase64(data []byte) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Lx4gH7Vdr5_y)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Lx4gH7Vdr5_y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1145,7 +1155,7 @@ func main() {
|
|||||||
func Sha1(str string) string
|
func Sha1(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_m_uoD1deMT)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_m_uoD1deMT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1176,7 +1186,7 @@ func main() {
|
|||||||
func Sha1WithBase64(str string) string
|
func Sha1WithBase64(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/fSyx-Gl2l2-)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fSyx-Gl2l2-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1205,7 +1215,7 @@ func main() {
|
|||||||
func Sha256(str string) string
|
func Sha256(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/tU9tfBMIAr1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tU9tfBMIAr1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1236,7 +1246,7 @@ func main() {
|
|||||||
func Sha256WithBase64(str string) string
|
func Sha256WithBase64(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/85IXJHIal1k)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/85IXJHIal1k)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1265,7 +1275,7 @@ func main() {
|
|||||||
func Sha512(str string) string
|
func Sha512(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/3WsvLYZxsHa)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/3WsvLYZxsHa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1296,7 +1306,7 @@ func main() {
|
|||||||
func Sha512WithBase64(str string) string
|
func Sha512WithBase64(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/q_fY2rA-k5I)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/q_fY2rA-k5I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1325,7 +1335,7 @@ func main() {
|
|||||||
func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error
|
func GenerateRsaKey(keySize int, priKeyFile, pubKeyFile string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/zutRHrDqs0X)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zutRHrDqs0X)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1353,7 +1363,7 @@ func main() {
|
|||||||
func RsaEncrypt(data []byte, pubKeyFileName string) []byte
|
func RsaEncrypt(data []byte, pubKeyFileName string) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1368,11 +1378,11 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := []byte("hello")
|
data := []byte("hello")
|
||||||
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
||||||
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
||||||
|
|
||||||
fmt.Println(string(decrypted))
|
fmt.Println(string(decrypted))
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -1380,7 +1390,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="RsaDecrypt">RsaDecrypt</span>
|
### <span id="RsaDecrypt">RsaDecrypt</span>
|
||||||
|
|
||||||
<p>Decrypt data with private key file useing ras algorithm.</p>
|
<p>Decrypt data with private key file useing ras algorithm.</p>
|
||||||
@@ -1391,7 +1400,7 @@ func main() {
|
|||||||
func RsaDecrypt(data []byte, privateKeyFileName string) []byte
|
func RsaDecrypt(data []byte, privateKeyFileName string) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uef0q1fz53I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1406,11 +1415,11 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := []byte("hello")
|
data := []byte("hello")
|
||||||
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
encrypted := cryptor.RsaEncrypt(data, "rsa_public.pem")
|
||||||
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
decrypted := cryptor.RsaDecrypt(encrypted, "rsa_private.pem")
|
||||||
|
|
||||||
fmt.Println(string(decrypted))
|
fmt.Println(string(decrypted))
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -1418,5 +1427,113 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="GenerateRsaKeyPair">GenerateRsaKeyPair</span>
|
||||||
|
|
||||||
|
<p>Creates rsa private and public key.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func GenerateRsaKeyPair(keySize int) (*rsa.PrivateKey, *rsa.PublicKey)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/cryptor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pri, pub := cryptor.GenerateRsaKeyPair(1024)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="RsaEncryptOAEP">RsaEncryptOAEP</span>
|
||||||
|
|
||||||
|
<p>Encrypts the given data with RSA-OAEP.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func RsaEncryptOAEP(data []byte, label []byte, key rsa.PublicKey) ([]byte, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/cryptor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pri, pub := cryptor.GenerateRsaKeyPair(1024)
|
||||||
|
|
||||||
|
data := []byte("hello world")
|
||||||
|
label := []byte("123456")
|
||||||
|
|
||||||
|
encrypted, err := cryptor.RsaEncryptOAEP(data, label, *pub)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypted, err := cryptor.RsaDecryptOAEP([]byte(encrypted), label, *pri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(decrypted))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// hello world
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="RsaDecryptOAEP">RsaDecryptOAEP</span>
|
||||||
|
|
||||||
|
<p>Decrypts the data with RSA-OAEP.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func RsaDecryptOAEP(ciphertext []byte, label []byte, key rsa.PrivateKey) ([]byte, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/cryptor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pri, pub := cryptor.GenerateRsaKeyPair(1024)
|
||||||
|
|
||||||
|
data := []byte("hello world")
|
||||||
|
label := []byte("123456")
|
||||||
|
|
||||||
|
encrypted, err := cryptor.RsaEncryptOAEP(data, label, *pub)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypted, err := cryptor.RsaDecryptOAEP([]byte(encrypted), label, *pri)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(decrypted))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// hello world
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import (
|
|||||||
|
|
||||||
### <span id="NewHashMap">NewHashMap</span>
|
### <span id="NewHashMap">NewHashMap</span>
|
||||||
|
|
||||||
<p>Make a HashMap instance with default capacity is 1 << 10.</p>
|
<p>Make a HashMap instance with default capacity is 1 << 10.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
## Note:
|
## Note:
|
||||||
@@ -109,7 +107,7 @@ import (
|
|||||||
func AddDay(t time.Time, day int64) time.Time
|
func AddDay(t time.Time, day int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/dIGbs_uTdFa)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/dIGbs_uTdFa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -148,7 +146,7 @@ func main() {
|
|||||||
func AddHour(t time.Time, hour int64) time.Time
|
func AddHour(t time.Time, hour int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/rcMjd7OCsi5)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/rcMjd7OCsi5)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -187,7 +185,7 @@ func main() {
|
|||||||
func AddMinute(t time.Time, minute int64) time.Time
|
func AddMinute(t time.Time, minute int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nT1heB1KUUK)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nT1heB1KUUK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -226,7 +224,7 @@ func main() {
|
|||||||
func AddYear(t time.Time, year int64) time.Time
|
func AddYear(t time.Time, year int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/MqW2ujnBx10)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/MqW2ujnBx10)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -265,7 +263,7 @@ func main() {
|
|||||||
func BeginOfMinute(t time.Time) time.Time
|
func BeginOfMinute(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ieOLVJ9CiFT)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ieOLVJ9CiFT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -297,7 +295,7 @@ func main() {
|
|||||||
func BeginOfHour(t time.Time) time.Time
|
func BeginOfHour(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/GhdGFnDWpYs)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/GhdGFnDWpYs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -329,7 +327,7 @@ func main() {
|
|||||||
func BeginOfDay(t time.Time) time.Time
|
func BeginOfDay(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/94m_UT6cWs9)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/94m_UT6cWs9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -361,7 +359,7 @@ func main() {
|
|||||||
func BeginOfWeek(t time.Time, beginFrom ...time.Weekday) time.Time
|
func BeginOfWeek(t time.Time, beginFrom ...time.Weekday) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ynjoJPz7VNV)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ynjoJPz7VNV)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -393,7 +391,7 @@ func main() {
|
|||||||
func BeginOfMonth(t time.Time) time.Time
|
func BeginOfMonth(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/bWXVFsmmzwL)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/bWXVFsmmzwL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -425,7 +423,7 @@ func main() {
|
|||||||
func BeginOfYear(t time.Time) time.Time
|
func BeginOfYear(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/i326DSwLnV8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/i326DSwLnV8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -457,7 +455,7 @@ func main() {
|
|||||||
func EndOfMinute(t time.Time) time.Time
|
func EndOfMinute(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/yrL5wGzPj4z)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/yrL5wGzPj4z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -489,7 +487,7 @@ func main() {
|
|||||||
func EndOfHour(t time.Time) time.Time
|
func EndOfHour(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/6ce3j_6cVqN)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/6ce3j_6cVqN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -521,7 +519,7 @@ func main() {
|
|||||||
func EndOfDay(t time.Time) time.Time
|
func EndOfDay(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/eMBOvmq5Ih1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/eMBOvmq5Ih1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -553,7 +551,7 @@ func main() {
|
|||||||
func EndOfWeek(t time.Time, endWith ...time.Weekday) time.Time
|
func EndOfWeek(t time.Time, endWith ...time.Weekday) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/i08qKXD9flf)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/i08qKXD9flf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -585,7 +583,7 @@ func main() {
|
|||||||
func EndOfMonth(t time.Time) time.Time
|
func EndOfMonth(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_GWh10B3Nqi)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_GWh10B3Nqi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -617,7 +615,7 @@ func main() {
|
|||||||
func EndOfYear(t time.Time) time.Time
|
func EndOfYear(t time.Time) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/G01cKlMCvNm)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/G01cKlMCvNm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -649,7 +647,7 @@ func main() {
|
|||||||
func GetNowDate() string
|
func GetNowDate() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/PvfkPpcpBBf)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/PvfkPpcpBBf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -678,7 +676,7 @@ func main() {
|
|||||||
func GetNowTime() string
|
func GetNowTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/l7BNxCkTmJS)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/l7BNxCkTmJS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -707,7 +705,7 @@ func main() {
|
|||||||
func GetNowDateTime() string
|
func GetNowDateTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/pI4AqngD0al)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pI4AqngD0al)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -736,7 +734,7 @@ func main() {
|
|||||||
func GetTodayStartTime() string
|
func GetTodayStartTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/84siyYF7t99)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/84siyYF7t99)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -765,7 +763,7 @@ func main() {
|
|||||||
func GetTodayEndTime() string
|
func GetTodayEndTime() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jjrLnfoqgn3)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jjrLnfoqgn3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -794,7 +792,7 @@ func main() {
|
|||||||
func GetZeroHourTimestamp() int64
|
func GetZeroHourTimestamp() int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/QmL2oIaGE3q)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/QmL2oIaGE3q)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -823,7 +821,7 @@ func main() {
|
|||||||
func GetNightTimestamp() int64
|
func GetNightTimestamp() int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/UolysR3MYP1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/UolysR3MYP1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -852,7 +850,7 @@ func main() {
|
|||||||
func FormatTimeToStr(t time.Time, format string, timezone ...string) string
|
func FormatTimeToStr(t time.Time, format string, timezone ...string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_Ia7M8H_OvE)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_Ia7M8H_OvE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -891,7 +889,7 @@ func main() {
|
|||||||
func FormatStrToTime(str, format string, timezone ...string) (time.Time, error)
|
func FormatStrToTime(str, format string, timezone ...string) (time.Time, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/1h9FwdU8ql4)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1h9FwdU8ql4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -930,7 +928,7 @@ type theTime struct {
|
|||||||
func NewUnixNow() *theTime
|
func NewUnixNow() *theTime
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/U4PPx-9D0oz)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/U4PPx-9D0oz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -962,7 +960,7 @@ type theTime struct {
|
|||||||
func NewUnix(unix int64) *theTime
|
func NewUnix(unix int64) *theTime
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/psoSuh_kLRt)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/psoSuh_kLRt)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -994,7 +992,7 @@ type theTime struct {
|
|||||||
func NewFormat(t string) (*theTime, error)
|
func NewFormat(t string) (*theTime, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1026,7 +1024,7 @@ type theTime struct {
|
|||||||
func NewISO8601(iso8601 string) (*theTime, error)
|
func NewISO8601(iso8601 string) (*theTime, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1055,7 +1053,7 @@ func main() {
|
|||||||
func (t *theTime) ToUnix() int64
|
func (t *theTime) ToUnix() int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_LUiwAdocjy)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_LUiwAdocjy)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1084,7 +1082,7 @@ func main() {
|
|||||||
func (t *theTime) ToFormat() string
|
func (t *theTime) ToFormat() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VkW08ZOaXPZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1113,7 +1111,7 @@ func main() {
|
|||||||
func (t *theTime) ToFormatForTpl(tpl string) string
|
func (t *theTime) ToFormatForTpl(tpl string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nyXxXcQJ8L5)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nyXxXcQJ8L5)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1143,7 +1141,7 @@ func main() {
|
|||||||
func (t *theTime) ToIso8601() string
|
func (t *theTime) ToIso8601() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/mkhOHQkdeA2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1173,7 +1171,7 @@ func main() {
|
|||||||
func IsLeapYear(year int) bool
|
func IsLeapYear(year int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/xS1eS2ejGew)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/xS1eS2ejGew)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1206,7 +1204,7 @@ func main() {
|
|||||||
func BetweenSeconds(t1 time.Time, t2 time.Time) int64
|
func BetweenSeconds(t1 time.Time, t2 time.Time) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/n3YDRyfyXJu)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/n3YDRyfyXJu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1243,7 +1241,7 @@ func main() {
|
|||||||
func DayOfYear(t time.Time) int
|
func DayOfYear(t time.Time) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/0hjqhTwFNlH)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/0hjqhTwFNlH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1284,7 +1282,7 @@ func main() {
|
|||||||
func IsWeekend(t time.Time) bool
|
func IsWeekend(t time.Time) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/cupRM5aZOIY)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/cupRM5aZOIY)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1324,7 +1322,7 @@ func main() {
|
|||||||
func NowDateOrTime(format string, timezone ...string) string
|
func NowDateOrTime(format string, timezone ...string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/EZ-begEjtT0)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/EZ-begEjtT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1358,7 +1356,7 @@ func main() {
|
|||||||
func Timestamp(timezone ...string) int64
|
func Timestamp(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/iU5b7Vvjx6x)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/iU5b7Vvjx6x)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1378,7 +1376,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="TimestampMilli">TimestampMilli</span>
|
### <span id="TimestampMilli">TimestampMilli</span>
|
||||||
|
|
||||||
<p>Return current mill second timestamp.</p>
|
<p>Return current mill second timestamp.</p>
|
||||||
@@ -1389,7 +1386,7 @@ func main() {
|
|||||||
func TimestampMilli(timezone ...string) int64
|
func TimestampMilli(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/4gvEusOTu1T)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4gvEusOTu1T)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1419,7 +1416,7 @@ func main() {
|
|||||||
func TimestampMicro(timezone ...string) int64
|
func TimestampMicro(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/2maANglKHQE)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/2maANglKHQE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1449,7 +1446,7 @@ func main() {
|
|||||||
func TimestampNano(timezone ...string) int64
|
func TimestampNano(timezone ...string) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/A9Oq_COrcCF)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/A9Oq_COrcCF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -47,11 +47,10 @@ import (
|
|||||||
- [WriteCsvFile](#WriteCsvFile)
|
- [WriteCsvFile](#WriteCsvFile)
|
||||||
- [WriteStringToFile](#WriteStringToFile)
|
- [WriteStringToFile](#WriteStringToFile)
|
||||||
- [WriteBytesToFile](#WriteBytesToFile)
|
- [WriteBytesToFile](#WriteBytesToFile)
|
||||||
|
- [ReadFile](#ReadFile)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="ClearFile">ClearFile</span>
|
### <span id="ClearFile">ClearFile</span>
|
||||||
@@ -64,7 +63,7 @@ import (
|
|||||||
func ClearFile(path string) error
|
func ClearFile(path string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/NRZ0ZT-G94H)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/NRZ0ZT-G94H)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -92,7 +91,7 @@ func main() {
|
|||||||
func CreateFile(path string) bool
|
func CreateFile(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/lDt8PEsTNKI)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/lDt8PEsTNKI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -118,7 +117,7 @@ func main() {
|
|||||||
func CreateDir(absPath string) error
|
func CreateDir(absPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/qUuCe1OGQnM)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qUuCe1OGQnM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -144,7 +143,7 @@ func main() {
|
|||||||
func CopyFile(srcPath string, dstPath string) error
|
func CopyFile(srcPath string, dstPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Jg9AMJMLrJi)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Jg9AMJMLrJi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -172,7 +171,7 @@ func main() {
|
|||||||
func CurrentPath() string
|
func CurrentPath() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/s74a9iBGcSw)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/s74a9iBGcSw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -198,7 +197,7 @@ func main() {
|
|||||||
func FileMode(path string) (fs.FileMode, error)
|
func FileMode(path string) (fs.FileMode, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/2l2hI42fA3p)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/2l2hI42fA3p)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -227,7 +226,7 @@ func main() {
|
|||||||
func MiMeType(file any) string
|
func MiMeType(file any) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/bd5sevSUZNu)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/bd5sevSUZNu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -258,7 +257,7 @@ func main() {
|
|||||||
func IsExist(path string) bool
|
func IsExist(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nKKXt8ZQbmh)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nKKXt8ZQbmh)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -285,7 +284,7 @@ func main() {
|
|||||||
func IsLink(path string) bool
|
func IsLink(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/TL-b-Kzvf44)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/TL-b-Kzvf44)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -311,7 +310,7 @@ func main() {
|
|||||||
func IsDir(path string) bool
|
func IsDir(path string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/WkVwEKqtOWk)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/WkVwEKqtOWk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -340,7 +339,7 @@ func main() {
|
|||||||
func ListFileNames(path string) ([]string, error)
|
func ListFileNames(path string) ([]string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Tjd7Y07rejl)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Tjd7Y07rejl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -366,7 +365,7 @@ func main() {
|
|||||||
func RemoveFile(path string) error
|
func RemoveFile(path string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/P2y0XW8a1SH)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/P2y0XW8a1SH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -394,7 +393,7 @@ func main() {
|
|||||||
func ReadFileToString(path string) (string, error)
|
func ReadFileToString(path string) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/cmfwp_5SQTp)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/cmfwp_5SQTp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -427,7 +426,7 @@ func main() {
|
|||||||
func ReadFileByLine(path string)([]string, error)
|
func ReadFileByLine(path string)([]string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/svJP_7ZrBrD)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/svJP_7ZrBrD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -461,7 +460,7 @@ func main() {
|
|||||||
func Zip(fpath string, destPath string) error
|
func Zip(fpath string, destPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/j-3sWBp8ik_P)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/j-3sWBp8ik_P)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -489,7 +488,7 @@ func main() {
|
|||||||
func ZipAppendEntry(fpath string, destPath string) error
|
func ZipAppendEntry(fpath string, destPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/cxvaT8TRNQp)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/cxvaT8TRNQp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -517,7 +516,7 @@ func main() {
|
|||||||
func UnZip(zipFile string, destPath string) error
|
func UnZip(zipFile string, destPath string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/g0w34kS7B8m)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/g0w34kS7B8m)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -545,7 +544,7 @@ func main() {
|
|||||||
func IsZipFile(filepath string) bool
|
func IsZipFile(filepath string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/9M0g2j_uF_e)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9M0g2j_uF_e)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -571,7 +570,7 @@ func main() {
|
|||||||
func FileSize(path string) (int64, error)
|
func FileSize(path string) (int64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/H9Z05uD-Jjc)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/H9Z05uD-Jjc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -603,7 +602,7 @@ func main() {
|
|||||||
func MTime(filepath string) (int64, error)
|
func MTime(filepath string) (int64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/s_Tl7lZoAaY)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/s_Tl7lZoAaY)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -635,7 +634,7 @@ func main() {
|
|||||||
func Sha(filepath string, shaType ...int) (string, error)
|
func Sha(filepath string, shaType ...int) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/VfEEcO2MJYf)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VfEEcO2MJYf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -673,7 +672,7 @@ func main() {
|
|||||||
func ReadCsvFile(filepath string) ([][]string, error)
|
func ReadCsvFile(filepath string) ([][]string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/OExTkhGEd3_u)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/OExTkhGEd3_u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -705,7 +704,7 @@ func main() {
|
|||||||
func WriteCsvFile(filepath string, records [][]string, append bool) error
|
func WriteCsvFile(filepath string, records [][]string, append bool) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/dAXm58Q5U1o)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/dAXm58Q5U1o)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -754,7 +753,7 @@ func main() {
|
|||||||
func WriteBytesToFile(filepath string, content []byte) error
|
func WriteBytesToFile(filepath string, content []byte) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/s7QlDxMj3P8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/s7QlDxMj3P8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -803,7 +802,7 @@ func main() {
|
|||||||
func WriteStringToFile(filepath string, content string, append bool) error
|
func WriteStringToFile(filepath string, content string, append bool) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/GhLS6d8lH_g)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/GhLS6d8lH_g)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -841,3 +840,41 @@ func main() {
|
|||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="ReadFile">ReadFile</span>
|
||||||
|
|
||||||
|
<p>Read File/URL</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;"> </span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/fileutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
reader, fn, err := ReadFile("https://httpbin.org/robots.txt")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer fn()
|
||||||
|
|
||||||
|
dat, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(string(dat))
|
||||||
|
// Output:
|
||||||
|
// User-agent: *
|
||||||
|
// Disallow: /deny
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="Comma">Comma</span>
|
### <span id="Comma">Comma</span>
|
||||||
@@ -47,7 +45,7 @@ import (
|
|||||||
func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string
|
func Comma[T constraints.Float | constraints.Integer | string](value T, symbol string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -83,7 +81,7 @@ func main() {
|
|||||||
func Pretty(v any) (string, error)
|
func Pretty(v any) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/YsciGj3FH2x)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/YsciGj3FH2x)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -122,7 +120,7 @@ func main() {
|
|||||||
func PrettyToWriter(v any, out io.Writer) error
|
func PrettyToWriter(v any, out io.Writer) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/LPLZ3lDi5ma)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/LPLZ3lDi5ma)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -165,7 +163,7 @@ func main() {
|
|||||||
func DecimalBytes(size float64, precision ...int) string
|
func DecimalBytes(size float64, precision ...int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/FPXs1suwRcs)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/FPXs1suwRcs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -204,7 +202,7 @@ func main() {
|
|||||||
func BinaryBytes(size float64, precision ...int) string
|
func BinaryBytes(size float64, precision ...int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/G9oHHMCAZxP)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/G9oHHMCAZxP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -243,7 +241,7 @@ func main() {
|
|||||||
func ParseDecimalBytes(size string) (uint64, error)
|
func ParseDecimalBytes(size string) (uint64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Am98ybWjvjj)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Am98ybWjvjj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -282,7 +280,7 @@ func main() {
|
|||||||
func ParseBinaryBytes(size string) (uint64, error)
|
func ParseBinaryBytes(size string) (uint64, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/69v1tTT62x8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/69v1tTT62x8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="After">After</span>
|
### <span id="After">After</span>
|
||||||
@@ -48,7 +47,7 @@ import (
|
|||||||
func After(n int, fn any) func(args ...any) []reflect.Value
|
func After(n int, fn any) func(args ...any) []reflect.Value
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/eRD5k2vzUVX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -81,7 +80,7 @@ func main() {
|
|||||||
func Before(n int, fn any) func(args ...any) []reflect.Value
|
func Before(n int, fn any) func(args ...any) []reflect.Value
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/0HqUDIFZ3IL)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/0HqUDIFZ3IL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -118,7 +117,7 @@ type CurryFn[T any] func(...T) T
|
|||||||
func (cf CurryFn[T]) New(val T) func(...T) T
|
func (cf CurryFn[T]) New(val T) func(...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/5HopfDwANKX)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/5HopfDwANKX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -157,7 +156,7 @@ func main() {
|
|||||||
func Compose[T any](fnList ...func(...T) T) func(...T) T
|
func Compose[T any](fnList ...func(...T) T) func(...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/KKfugD4PKYF)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KKfugD4PKYF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -195,7 +194,7 @@ func main() {
|
|||||||
func Debounced(fn func(), duration time.Duration) func()
|
func Debounced(fn func(), duration time.Duration) func()
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/absuEGB_GN7)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/absuEGB_GN7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -245,7 +244,7 @@ func main() {
|
|||||||
func Delay(delay time.Duration, fn any, args ...any)
|
func Delay(delay time.Duration, fn any, args ...any)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Ivtc2ZE-Tye)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Ivtc2ZE-Tye)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -277,7 +276,7 @@ func main() {
|
|||||||
func Schedule(d time.Duration, fn any, args ...any) chan bool
|
func Schedule(d time.Duration, fn any, args ...any) chan bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/hbON-Xeyn5N)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/hbON-Xeyn5N)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -317,7 +316,7 @@ the functions one by one.</p>
|
|||||||
func Pipeline[T any](funcs ...func(T) T) func(T) T
|
func Pipeline[T any](funcs ...func(T) T) func(T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/mPdUVvj6HD6)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/mPdUVvj6HD6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -368,7 +367,7 @@ func (w *Watcher) Reset() //reset the watcher
|
|||||||
func (w *Watcher) GetElapsedTime() time.Duration //get the elapsed time of function execution
|
func (w *Watcher) GetElapsedTime() time.Duration //get the elapsed time of function execution
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/l2yrOpCLd1I)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/l2yrOpCLd1I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="MapTo">MapTo</span>
|
### <span id="MapTo">MapTo</span>
|
||||||
@@ -69,7 +67,7 @@ import (
|
|||||||
func MapTo(src any, dst any) error
|
func MapTo(src any, dst any) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/4K7KBEPgS5M)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4K7KBEPgS5M)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -126,7 +124,7 @@ func main() {
|
|||||||
func ForEach[K comparable, V any](m map[K]V, iteratee func(key K, value V))
|
func ForEach[K comparable, V any](m map[K]V, iteratee func(key K, value V))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/OaThj6iNVXK)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/OaThj6iNVXK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -167,7 +165,7 @@ func main() {
|
|||||||
func Filter[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
func Filter[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/fSvF3wxuNG7)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fSvF3wxuNG7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -212,7 +210,7 @@ func main() {
|
|||||||
func FilterByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
func FilterByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/7ov6BJHbVqh)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/7ov6BJHbVqh)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -250,7 +248,7 @@ func main() {
|
|||||||
func FilterByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
func FilterByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/P3-9MdcXegR)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/P3-9MdcXegR)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -288,7 +286,7 @@ func main() {
|
|||||||
func OmitBy[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
func OmitBy[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/YJM4Hj5hNwm)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/YJM4Hj5hNwm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -329,7 +327,7 @@ func main() {
|
|||||||
func OmitByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
func OmitByKeys[K comparable, V any](m map[K]V, keys []K) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jXGrWDBfSRp)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jXGrWDBfSRp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -367,7 +365,7 @@ func main() {
|
|||||||
func OmitByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
func OmitByValues[K comparable, V comparable](m map[K]V, values []V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/XB7Y10uw20_U)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/XB7Y10uw20_U)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -405,7 +403,7 @@ func main() {
|
|||||||
func Intersect[K comparable, V any](maps ...map[K]V) map[K]V
|
func Intersect[K comparable, V any](maps ...map[K]V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Zld0oj3sjcC)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Zld0oj3sjcC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -460,7 +458,7 @@ func main() {
|
|||||||
func Keys[K comparable, V any](m map[K]V) []K
|
func Keys[K comparable, V any](m map[K]V) []K
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/xNB5bTb97Wd)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/xNB5bTb97Wd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -500,7 +498,7 @@ func main() {
|
|||||||
func Merge[K comparable, V any](maps ...map[K]V) map[K]V
|
func Merge[K comparable, V any](maps ...map[K]V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/H95LENF1uB-)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/H95LENF1uB-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -539,7 +537,7 @@ func main() {
|
|||||||
func Minus[K comparable, V any](mapA, mapB map[K]V) map[K]V
|
func Minus[K comparable, V any](mapA, mapB map[K]V) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/3u5U9K7YZ9m)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/3u5U9K7YZ9m)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -581,7 +579,7 @@ func main() {
|
|||||||
func Values[K comparable, V any](m map[K]V) []V
|
func Values[K comparable, V any](m map[K]V) []V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/CBKdUc5FTW6)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/CBKdUc5FTW6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -621,7 +619,7 @@ func main() {
|
|||||||
func KeysBy[K comparable, V any, T any](m map[K]V, mapper func(item K) T) []T
|
func KeysBy[K comparable, V any, T any](m map[K]V, mapper func(item K) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/hI371iB8Up8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/hI371iB8Up8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -662,7 +660,7 @@ func main() {
|
|||||||
func ValuesBy[K comparable, V any, T any](m map[K]V, mapper func(item V) T) []T
|
func ValuesBy[K comparable, V any, T any](m map[K]V, mapper func(item V) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/sg9-oRidh8f)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/sg9-oRidh8f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -711,7 +709,7 @@ func main() {
|
|||||||
func MapKeys[K comparable, V any, T comparable](m map[K]V, iteratee func(key K, value V) T) map[T]V
|
func MapKeys[K comparable, V any, T comparable](m map[K]V, iteratee func(key K, value V) T) map[T]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/8scDxWeBDKd)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/8scDxWeBDKd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -750,7 +748,7 @@ func main() {
|
|||||||
func MapValues[K comparable, V any, T any](m map[K]V, iteratee func(key K, value V) T) map[K]T
|
func MapValues[K comparable, V any, T any](m map[K]V, iteratee func(key K, value V) T) map[K]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/g92aY3fc7Iw)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/g92aY3fc7Iw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -793,7 +791,7 @@ type Entry[K comparable, V any] struct {
|
|||||||
func Entries[K comparable, V any](m map[K]V) []Entry[K, V]
|
func Entries[K comparable, V any](m map[K]V) []Entry[K, V]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Ltb11LNcElY)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Ltb11LNcElY)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -838,7 +836,7 @@ type Entry[K comparable, V any] struct {
|
|||||||
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
|
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/fTdu4sCNjQO)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fTdu4sCNjQO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -872,7 +870,7 @@ func main() {
|
|||||||
func Transform[K1 comparable, V1 any, K2 comparable, V2 any](m map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2
|
func Transform[K1 comparable, V1 any, K2 comparable, V2 any](m map[K1]V1, iteratee func(key K1, value V1) (K2, V2)) map[K2]V2
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/P6ovfToM3zj)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/P6ovfToM3zj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -911,7 +909,7 @@ func main() {
|
|||||||
func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
|
func IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -966,7 +964,7 @@ if haskey {
|
|||||||
func HasKey[K comparable, V any](m map[K]V, key K) bool
|
func HasKey[K comparable, V any](m map[K]V, key K) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/isZZHOsDhFc)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/isZZHOsDhFc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1005,7 +1003,7 @@ func main() {
|
|||||||
func NewConcurrentMap[K comparable, V any](shardCount int) *ConcurrentMap[K, V]
|
func NewConcurrentMap[K comparable, V any](shardCount int) *ConcurrentMap[K, V]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1031,7 +1029,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Set(key K, value V)
|
func (cm *ConcurrentMap[K, V]) Set(key K, value V)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1086,7 +1084,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Get(key K) (V, bool)
|
func (cm *ConcurrentMap[K, V]) Get(key K) (V, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/3PenTPETJT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1141,7 +1139,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) GetOrSet(key K, value V) (actual V, ok bool)
|
func (cm *ConcurrentMap[K, V]) GetOrSet(key K, value V) (actual V, ok bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/aDcDApOK01a)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/aDcDApOK01a)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1185,7 +1183,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Delete(key K)
|
func (cm *ConcurrentMap[K, V]) Delete(key K)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/uTIJZYhpVMS)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uTIJZYhpVMS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1232,7 +1230,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) GetAndDelete(key K) (actual V, ok bool)
|
func (cm *ConcurrentMap[K, V]) GetAndDelete(key K) (actual V, ok bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ZyxeIXSZUiM)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ZyxeIXSZUiM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1284,7 +1282,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Has(key K) bool
|
func (cm *ConcurrentMap[K, V]) Has(key K) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/C8L4ul9TVwf)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/C8L4ul9TVwf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1331,7 +1329,7 @@ func main() {
|
|||||||
func (cm *ConcurrentMap[K, V]) Range(iterator func(key K, value V) bool)
|
func (cm *ConcurrentMap[K, V]) Range(iterator func(key K, value V) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/iqcy7P8P0Pr)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/iqcy7P8P0Pr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="Average">Average</span>
|
### <span id="Average">Average</span>
|
||||||
@@ -64,7 +62,7 @@ import (
|
|||||||
func Average[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Average[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Vv7LBwER-pz)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Vv7LBwER-pz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -99,7 +97,7 @@ func main() {
|
|||||||
func Exponent(x, n int64) int64
|
func Exponent(x, n int64) int64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/uF3HGNPk8wr)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uF3HGNPk8wr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -135,7 +133,7 @@ func main() {
|
|||||||
func Fibonacci(first, second, n int) int
|
func Fibonacci(first, second, n int) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/IscseUNMuUc)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/IscseUNMuUc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -171,7 +169,7 @@ func main() {
|
|||||||
func Factorial(x uint) uint
|
func Factorial(x uint) uint
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/tt6LdOK67Nx)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tt6LdOK67Nx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -207,7 +205,7 @@ func main() {
|
|||||||
func Max[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Max[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/cN8DHI0rTkH)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/cN8DHI0rTkH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -240,7 +238,7 @@ func main() {
|
|||||||
func MaxBy[T any](slice []T, comparator func(T, T) bool) T
|
func MaxBy[T any](slice []T, comparator func(T, T) bool) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/pbe2MT-7DV2)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pbe2MT-7DV2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -284,7 +282,7 @@ func main() {
|
|||||||
func Min[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Min[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/21BER_mlGUj)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/21BER_mlGUj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -317,7 +315,7 @@ func main() {
|
|||||||
func MinBy[T any](slice []T, comparator func(T, T) bool) T
|
func MinBy[T any](slice []T, comparator func(T, T) bool) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/N9qgYg_Ho6f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -361,7 +359,7 @@ func main() {
|
|||||||
func Percent(val, total float64, n int) float64
|
func Percent(val, total float64, n int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/s0NdFCtwuyd)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/s0NdFCtwuyd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -397,7 +395,7 @@ func main() {
|
|||||||
func RoundToFloat(x float64, n int) float64
|
func RoundToFloat(x float64, n int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ghyb528JRJL)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ghyb528JRJL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -433,7 +431,7 @@ func main() {
|
|||||||
func RoundToString(x float64, n int) string
|
func RoundToString(x float64, n int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/kZwpBRAcllO)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/kZwpBRAcllO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -469,7 +467,7 @@ func main() {
|
|||||||
func TruncRound(x float64, n int) float64
|
func TruncRound(x float64, n int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/aumarSHIGzP)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/aumarSHIGzP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -505,7 +503,7 @@ func main() {
|
|||||||
func Range[T constraints.Integer | constraints.Float](start T, count int) []T
|
func Range[T constraints.Integer | constraints.Float](start T, count int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/9ke2opxa8ZP)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9ke2opxa8ZP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -544,7 +542,7 @@ func main() {
|
|||||||
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T
|
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/akLWz0EqOSM)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/akLWz0EqOSM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -583,7 +581,7 @@ func main() {
|
|||||||
func AngleToRadian(angle float64) float64
|
func AngleToRadian(angle float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/CIvlICqrHql)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/CIvlICqrHql)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -619,7 +617,7 @@ func main() {
|
|||||||
func RadianToAngle(radian float64) float64
|
func RadianToAngle(radian float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/dQtmOTUOMgi)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/dQtmOTUOMgi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -655,7 +653,7 @@ func main() {
|
|||||||
func PointDistance(x1, y1, x2, y2 float64) float64
|
func PointDistance(x1, y1, x2, y2 float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/RrG4JIaziM8)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/RrG4JIaziM8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -685,7 +683,7 @@ func main() {
|
|||||||
func IsPrime(n int) bool
|
func IsPrime(n int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Rdd8UTHZJ7u)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Rdd8UTHZJ7u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -724,7 +722,7 @@ func main() {
|
|||||||
func GCD[T constraints.Integer](integers ...T) T
|
func GCD[T constraints.Integer](integers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/CiEceLSoAKB)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/CiEceLSoAKB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -766,7 +764,7 @@ func main() {
|
|||||||
func LCM[T constraints.Integer](integers ...T) T
|
func LCM[T constraints.Integer](integers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/EjcZxfY7G_g)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/EjcZxfY7G_g)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -802,7 +800,7 @@ func main() {
|
|||||||
func Cos(radian float64, precision ...int) float64
|
func Cos(radian float64, precision ...int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Sm89LoIfvFq)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Sm89LoIfvFq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -844,7 +842,7 @@ func main() {
|
|||||||
func Sin(radian float64, precision ...int) float64
|
func Sin(radian float64, precision ...int) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/TWMQlMywDsP)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/TWMQlMywDsP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -886,7 +884,7 @@ func main() {
|
|||||||
func Log(n, base float64) float64
|
func Log(n, base float64) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/_d4bi8oyhat)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_d4bi8oyhat)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -922,7 +920,7 @@ func main() {
|
|||||||
func Sum[T constraints.Integer | constraints.Float](numbers ...T) T
|
func Sum[T constraints.Integer | constraints.Float](numbers ...T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/1To2ImAMJA7)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1To2ImAMJA7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -955,7 +953,7 @@ func main() {
|
|||||||
func Abs[T constraints.Integer | constraints.Float](x T) T
|
func Abs[T constraints.Integer | constraints.Float](x T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/fsyBh1Os-1d)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fsyBh1Os-1d)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ import (
|
|||||||
func ConvertMapToQueryString(param map[string]any) string
|
func ConvertMapToQueryString(param map[string]any) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jnNt_qoSnRi)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jnNt_qoSnRi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -98,7 +98,7 @@ func main() {
|
|||||||
func EncodeUrl(urlStr string) (string, error)
|
func EncodeUrl(urlStr string) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/bsZ6BRC4uKI)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/bsZ6BRC4uKI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -133,7 +133,7 @@ func main() {
|
|||||||
func GetInternalIp() string
|
func GetInternalIp() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/5mbu-gFp7ei)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/5mbu-gFp7ei)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -165,7 +165,7 @@ func main() {
|
|||||||
func GetIps() []string
|
func GetIps() []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/NUFfcEmukx1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/NUFfcEmukx1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -195,7 +195,7 @@ func main() {
|
|||||||
func GetMacAddrs() []string {
|
func GetMacAddrs() []string {
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/Rq9UUBS_Xp1)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Rq9UUBS_Xp1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -239,7 +239,7 @@ type PublicIpInfo struct {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/YDxIfozsRHR)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/YDxIfozsRHR)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -269,7 +269,7 @@ func main() {
|
|||||||
func GetRequestPublicIp(req *http.Request) string
|
func GetRequestPublicIp(req *http.Request) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/kxU-YDc_eBo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/kxU-YDc_eBo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -307,7 +307,7 @@ func main() {
|
|||||||
func IsPublicIP(IP net.IP) bool
|
func IsPublicIP(IP net.IP) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/nmktSQpJZnn)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nmktSQpJZnn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -344,7 +344,7 @@ func main() {
|
|||||||
func IsInternalIP(IP net.IP) bool
|
func IsInternalIP(IP net.IP) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/sYGhXbgO4Cb)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/sYGhXbgO4Cb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -388,7 +388,7 @@ type HttpRequest struct {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -445,7 +445,7 @@ func NewHttpClientWithConfig(config *HttpClientConfig) *HttpClient
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -476,7 +476,7 @@ func main() {
|
|||||||
func (client *HttpClient) SendRequest(request *HttpRequest) (*http.Response, error)
|
func (client *HttpClient) SendRequest(request *HttpRequest) (*http.Response, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -530,7 +530,7 @@ func main() {
|
|||||||
func (client *HttpClient) DecodeResponse(resp *http.Response, target any) error
|
func (client *HttpClient) DecodeResponse(resp *http.Response, target any) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jUSgynekH7G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -584,7 +584,7 @@ func main() {
|
|||||||
func StructToUrlValues(targetStruct any) url.Values
|
func StructToUrlValues(targetStruct any) url.Values
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/pFqMkM40w9z)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pFqMkM40w9z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -966,7 +966,7 @@ func main() {
|
|||||||
func IsPingConnected(host string) bool
|
func IsPingConnected(host string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/q8OzTijsA87)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/q8OzTijsA87)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -999,7 +999,7 @@ func main() {
|
|||||||
func IsTelnetConnected(host string, port string) bool
|
func IsTelnetConnected(host string, port string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/yiLCGtQv_ZG)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/yiLCGtQv_ZG)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="Of">Of</span>
|
### <span id="Of">Of</span>
|
||||||
@@ -44,7 +42,7 @@ import (
|
|||||||
func Of[T any](v T) *T
|
func Of[T any](v T) *T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/HFd70x4DrMj)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/HFd70x4DrMj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -78,7 +76,7 @@ func main() {
|
|||||||
func Unwrap[T any](p *T) T
|
func Unwrap[T any](p *T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/cgeu3g7cjWb)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/cgeu3g7cjWb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -114,7 +112,7 @@ func main() {
|
|||||||
UnwarpOr[T any](p *T, fallback T) T
|
UnwarpOr[T any](p *T, fallback T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/mmNaLC38W8C)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/mmNaLC38W8C)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -159,7 +157,7 @@ func main() {
|
|||||||
UnwarpOrDefault[T any](p *T) T
|
UnwarpOrDefault[T any](p *T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/ZnGIHf8_o4E)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ZnGIHf8_o4E)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -205,7 +203,7 @@ func main() {
|
|||||||
func ExtractPointer(value any) any
|
func ExtractPointer(value any) any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span class="run-container">[Run](https://go.dev/play/p/D7HFjeWU2ZP)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/D7HFjeWU2ZP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import (
|
|||||||
func RandBytes(length int) []byte
|
func RandBytes(length int) []byte
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/EkiLESeXf8d)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -72,7 +72,7 @@ func main() {
|
|||||||
func RandInt(min, max int) int
|
func RandInt(min, max int) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pXyyAAI5YxD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -98,7 +98,7 @@ func main() {
|
|||||||
func RandString(length int) string
|
func RandString(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/W2xvRUXA7Mi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -124,7 +124,7 @@ func main() {
|
|||||||
func RandUpper(length int) string
|
func RandUpper(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/29QfOh0DVuh)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -150,7 +150,7 @@ func main() {
|
|||||||
func RandLower(length int) string
|
func RandLower(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/XJtZ471cmtI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -176,7 +176,7 @@ func main() {
|
|||||||
func RandNumeral(length int) string
|
func RandNumeral(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/g4JWVpHsJcf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -202,7 +202,7 @@ func main() {
|
|||||||
func RandNumeralOrLetter(length int) string
|
func RandNumeralOrLetter(length int) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/19CEQvpx2jD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -228,7 +228,7 @@ func main() {
|
|||||||
func UUIdV4() (string, error)
|
func UUIdV4() (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_Z9SFmr28ft)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -258,7 +258,7 @@ func main() {
|
|||||||
func RandUniqueIntSlice(n, min, max int) []int
|
func RandUniqueIntSlice(n, min, max int) []int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uBkRSOz73Ec)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -42,7 +42,7 @@ import (
|
|||||||
func Context(ctx context.Context)
|
func Context(ctx context.Context)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/xnAOOXv9GkS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -89,7 +89,7 @@ func main() {
|
|||||||
type RetryFunc func() error
|
type RetryFunc func() error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -135,7 +135,7 @@ func main() {
|
|||||||
func RetryTimes(n uint)
|
func RetryTimes(n uint)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ssfVeU2SwLO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -178,7 +178,7 @@ func main() {
|
|||||||
func RetryDuration(d time.Duration)
|
func RetryDuration(d time.Duration)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -224,7 +224,7 @@ func main() {
|
|||||||
func Retry(retryFunc RetryFunc, opts ...Option) error
|
func Retry(retryFunc RetryFunc, opts ...Option) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nk2XRmagfVF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -77,7 +77,7 @@ import (
|
|||||||
- [IsSortedByKey](#IsSortedByKey)
|
- [IsSortedByKey](#IsSortedByKey)
|
||||||
- [Sort](#Sort)
|
- [Sort](#Sort)
|
||||||
- [SortBy](#SortBy)
|
- [SortBy](#SortBy)
|
||||||
- [SortByField<sup>deprecated</sup>](#SortByField)
|
- [SortByField](#SortByField)
|
||||||
- [Some](#Some)
|
- [Some](#Some)
|
||||||
- [StringSlice<sup>deprecated</sup>](#StringSlice)
|
- [StringSlice<sup>deprecated</sup>](#StringSlice)
|
||||||
- [SymmetricDifference](#SymmetricDifference)
|
- [SymmetricDifference](#SymmetricDifference)
|
||||||
@@ -91,6 +91,7 @@ import (
|
|||||||
- [Without](#Without)
|
- [Without](#Without)
|
||||||
- [KeyBy](#KeyBy)
|
- [KeyBy](#KeyBy)
|
||||||
- [Join](#Join)
|
- [Join](#Join)
|
||||||
|
- [Partition](#Partition)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ import (
|
|||||||
func AppendIfAbsent[T comparable](slice []T, item T) []T
|
func AppendIfAbsent[T comparable](slice []T, item T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/GNdv7Jg2Taj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -137,7 +138,7 @@ func main() {
|
|||||||
func Contain[T comparable](slice []T, target T) bool
|
func Contain[T comparable](slice []T, target T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_454yEHcNjf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -168,7 +169,7 @@ func main() {
|
|||||||
func ContainBy[T any](slice []T, predicate func(item T) bool) bool
|
func ContainBy[T any](slice []T, predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/49tkHfX4GNc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -213,7 +214,7 @@ func main() {
|
|||||||
func ContainSubSlice[T comparable](slice, subSlice []T) bool
|
func ContainSubSlice[T comparable](slice, subSlice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/bcuQ3UT6Sev)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -244,7 +245,7 @@ func main() {
|
|||||||
func Chunk[T any](slice []T, size int) [][]T
|
func Chunk[T any](slice []T, size int) [][]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/b4Pou5j2L_C)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -286,7 +287,7 @@ func main() {
|
|||||||
func Compact[T comparable](slice []T) []T
|
func Compact[T comparable](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pO5AnxEr3TK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -323,7 +324,7 @@ func main() {
|
|||||||
func Concat[T any](slice []T, slices ...[]T) []T
|
func Concat[T any](slice []T, slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/gPt-q7zr5mk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -354,7 +355,7 @@ func main() {
|
|||||||
func Count[T comparable](slice []T, item T) int
|
func Count[T comparable](slice []T, item T) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Mj4oiEnQvRJ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -387,7 +388,7 @@ func main() {
|
|||||||
func CountBy[T any](slice []T, predicate func(index int, item T) bool) int
|
func CountBy[T any](slice []T, predicate func(index int, item T) bool) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tHOccTMDZCC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -421,7 +422,7 @@ func main() {
|
|||||||
func Difference[T comparable](slice, comparedSlice []T) []T
|
func Difference[T comparable](slice, comparedSlice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VXvadzLzhDa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -452,7 +453,7 @@ func main() {
|
|||||||
func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
func DifferenceBy[T comparable](slice []T, comparedSlice []T, iteratee func(index int, item T) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DiivgwM5OnC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -487,7 +488,7 @@ func main() {
|
|||||||
func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
|
func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value, otherValue T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/v2U2deugKuV)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -522,7 +523,7 @@ func main() {
|
|||||||
func DeleteAt[T any](slice []T, start int, end ...int)
|
func DeleteAt[T any](slice []T, start int, end ...int)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pJ-d6MUWcvK)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -556,7 +557,7 @@ func main() {
|
|||||||
func Drop[T any](slice []T, n int) []T
|
func Drop[T any](slice []T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jnPO2yQsT8H)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -593,7 +594,7 @@ func main() {
|
|||||||
func DropRight[T any](slice []T, n int) []T
|
func DropRight[T any](slice []T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/8bcXvywZezG)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -630,7 +631,7 @@ func main() {
|
|||||||
func DropWhile[T any](slice []T, predicate func(item T) bool) []T
|
func DropWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4rt252UV_qs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -670,7 +671,7 @@ func main() {
|
|||||||
func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T
|
func DropRightWhile[T any](slice []T, predicate func(item T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/6wyK3zMY56e)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -712,7 +713,7 @@ func main() {
|
|||||||
func Equal[T comparable](slice1, slice2 []T) bool
|
func Equal[T comparable](slice1, slice2 []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/WcRQJ37ifPa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -747,7 +748,7 @@ func main() {
|
|||||||
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/b9iygtgsHI1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -782,7 +783,7 @@ func main() {
|
|||||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
func Every[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/R8U6Sl-j8cD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -816,7 +817,7 @@ func main() {
|
|||||||
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
func Filter[T any](slice []T, predicate func(index int, item T) bool) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/SdPna-7qK4T)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -850,7 +851,7 @@ func main() {
|
|||||||
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
func Find[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/CBKeBoHVLgq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -878,7 +879,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="FindBy">FindBy</span>
|
### <span id="FindBy">FindBy</span>
|
||||||
|
|
||||||
<p>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. In contrast to Find or FindLast, its return value no longer requires dereferencing</p>
|
<p>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. In contrast to Find or FindLast, its return value no longer requires dereferencing.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -886,7 +887,7 @@ func main() {
|
|||||||
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)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/n1lysBYl-GB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -922,7 +923,7 @@ func main() {
|
|||||||
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
func FindLast[T any](slice []T, predicate func(index int, item T) bool) (*T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/FFDPV_j7URd)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -950,7 +951,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="FindLastBy">FindLastBy</span>
|
### <span id="FindLastBy">FindLastBy</span>
|
||||||
|
|
||||||
<p>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. In contrast to Find or FindLast, its return value no longer requires dereferencing</p>
|
<p>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. In contrast to Find or FindLast, its return value no longer requires dereferencing.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -958,7 +959,7 @@ func main() {
|
|||||||
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)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/8iqomzyCl_s)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -994,7 +995,7 @@ func main() {
|
|||||||
func Flatten(slice any) any
|
func Flatten(slice any) any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/hYa3cBEevtm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1024,7 +1025,7 @@ func main() {
|
|||||||
func FlattenDeep(slice any) any
|
func FlattenDeep(slice any) any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/yjYNHPyCFaF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1054,7 +1055,7 @@ func main() {
|
|||||||
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
func ForEach[T any](slice []T, iteratee func(index int, item T))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DrPaa4YsHRF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1089,7 +1090,7 @@ func main() {
|
|||||||
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool)
|
func ForEachWithBreak[T any](slice []T, iteratee func(index int, item T) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qScs39f3D9W)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1127,7 +1128,7 @@ func main() {
|
|||||||
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
func GroupBy[T any](slice []T, groupFn func(index int, item T) bool) ([]T, []T)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/QVkPxzPR0iA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1163,7 +1164,7 @@ func main() {
|
|||||||
func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T
|
func GroupWith[T any, U comparable](slice []T, iteratee func(T) U) map[U][]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ApCvMNTLO8a)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1197,7 +1198,7 @@ func main() {
|
|||||||
func IntSlice(slice any) []int
|
func IntSlice(slice any) []int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/UQDj-on9TGN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1226,7 +1227,7 @@ func main() {
|
|||||||
func InterfaceSlice(slice any) []any
|
func InterfaceSlice(slice any) []any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/FdQXF0Vvqs-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1255,7 +1256,7 @@ func main() {
|
|||||||
func Intersection[T comparable](slices ...[]T) []T
|
func Intersection[T comparable](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/anJXfB5wq_t)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1286,7 +1287,7 @@ func main() {
|
|||||||
func InsertAt[T any](slice []T, index int, value any) []T
|
func InsertAt[T any](slice []T, index int, value any) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/hMLNxPEGJVE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1326,7 +1327,7 @@ func main() {
|
|||||||
func IndexOf[T comparable](slice []T, item T) int
|
func IndexOf[T comparable](slice []T, item T) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/MRN1f0FpABb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1359,7 +1360,7 @@ func main() {
|
|||||||
func LastIndexOf[T comparable](slice []T, item T) int
|
func LastIndexOf[T comparable](slice []T, item T) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DokM4cf1IKH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1392,7 +1393,7 @@ func main() {
|
|||||||
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/biaTefqPquw)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1426,7 +1427,7 @@ func main() {
|
|||||||
func FilterMap[T any, U any](slice []T, iteratee func(index int, item T) (U, bool)) []U
|
func FilterMap[T any, U any](slice []T, iteratee func(index int, item T) (U, bool)) []U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/J94SZ_9MiIe)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1463,7 +1464,7 @@ func main() {
|
|||||||
func FlatMap[T any, U any](slice []T, iteratee func(index int, item T) []U) []U
|
func FlatMap[T any, U any](slice []T, iteratee func(index int, item T) []U) []U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_QARWlWs1N_F)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1496,7 +1497,7 @@ func main() {
|
|||||||
func Merge[T any](slices ...[]T) []T
|
func Merge[T any](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/lbjFp784r9N)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1527,7 +1528,7 @@ func main() {
|
|||||||
func Reverse[T any](slice []T)
|
func Reverse[T any](slice []T)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/8uI8f1lwNrQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1557,7 +1558,7 @@ func main() {
|
|||||||
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
func Reduce[T any](slice []T, iteratee func(index int, item1, item2 T) T, initial T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/_RfXJJWIsIm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1591,7 +1592,7 @@ func main() {
|
|||||||
func ReduceBy[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
func ReduceBy[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/YKDpLi7gtee)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1627,7 +1628,7 @@ func main() {
|
|||||||
func ReduceRight[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
func ReduceRight[T any, U any](slice []T, initial U, reducer func(index int, item T, agg U) U) U
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qT9dZC03A1K)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1657,7 +1658,7 @@ func main() {
|
|||||||
func Replace[T comparable](slice []T, old T, new T, n int) []T
|
func Replace[T comparable](slice []T, old T, new T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/P5mZp7IhOFo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1699,7 +1700,7 @@ func main() {
|
|||||||
func ReplaceAll[T comparable](slice []T, old T, new T) []T
|
func ReplaceAll[T comparable](slice []T, old T, new T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/CzqXMsuYUrx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1727,7 +1728,7 @@ func main() {
|
|||||||
func Repeat[T any](item T, n int) []T
|
func Repeat[T any](item T, n int) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1755,7 +1756,7 @@ func main() {
|
|||||||
func Shuffle[T any](slice []T) []T
|
func Shuffle[T any](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/YHvhnWGU3Ge)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1784,7 +1785,7 @@ func main() {
|
|||||||
func IsAscending[T constraints.Ordered](slice []T) bool
|
func IsAscending[T constraints.Ordered](slice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9CtsFjet4SH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1818,7 +1819,7 @@ func main() {
|
|||||||
func IsDescending[T constraints.Ordered](slice []T) bool
|
func IsDescending[T constraints.Ordered](slice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/U_LljFXma14)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1852,7 +1853,7 @@ func main() {
|
|||||||
func IsSorted[T constraints.Ordered](slice []T) bool
|
func IsSorted[T constraints.Ordered](slice []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/nCE8wPLwSA-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1886,7 +1887,7 @@ func main() {
|
|||||||
func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
|
func IsSortedByKey[T any, K constraints.Ordered](slice []T, iteratee func(item T) K) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tUoGB7DOHI4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1918,8 +1919,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="Sort">Sort</span>
|
### <span id="Sort">Sort</span>
|
||||||
|
|
||||||
<p>Sorts a slice of any ordered type(number or string), use quick sort algrithm. Default sort order is ascending (asc), if want descending order, set param `sortOrder` to `desc`. Ordered type: number(all ints uints floats) or string.
|
<p>Sorts a slice of any ordered type(number or string), use quick sort algrithm. Default sort order is ascending (asc), if want descending order, set param `sortOrder` to `desc`. Ordered type: number(all ints uints floats) or string.</p>
|
||||||
</p>
|
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -1927,7 +1927,7 @@ func main() {
|
|||||||
func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
|
func Sort[T constraints.Ordered](slice []T, sortOrder ...string)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/V9AVjzf_4Fk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1956,7 +1956,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="SortBy">SortBy</span>
|
### <span id="SortBy">SortBy</span>
|
||||||
|
|
||||||
<p>Sorts the slice in ascending order as determined by the less function. This sort is not guaranteed to be stable.<p>
|
<p>Sorts the slice in ascending order as determined by the less function. This sort is not guaranteed to be stable.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -1964,7 +1964,7 @@ func main() {
|
|||||||
func SortBy[T any](slice []T, less func(a, b T) bool)
|
func SortBy[T any](slice []T, less func(a, b T) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DAhLQSZEumm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2001,9 +2001,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="SortByField">SortByField (Deprecated: use Sort and SortBy for replacement)</span>
|
### <span id="SortByField">SortByField</span>
|
||||||
|
|
||||||
<p>Sort struct slice by field. Slice element should be struct, field type should be int, uint, string, or bool. Default sort type is ascending (asc), if descending order, set sortType to desc</p>
|
<p>Sort struct slice by field. Slice element should be struct, `field` param type should be int, uint, string, or bool. Default sort type is ascending (asc), if descending order, set `sortType` param to desc.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -2011,7 +2011,7 @@ func main() {
|
|||||||
func SortByField(slice any, field string, sortType ...string) error
|
func SortByField(slice any, field string, sortType ...string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fU1prOBP9p1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2052,7 +2052,7 @@ func main() {
|
|||||||
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
func Some[T any](slice []T, predicate func(index int, item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4pO9Xf9NDGS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2086,7 +2086,7 @@ func main() {
|
|||||||
func StringSlice(slice any) []string
|
func StringSlice(slice any) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/W0TZDWCPFcI)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2115,7 +2115,7 @@ func main() {
|
|||||||
func SymmetricDifference[T comparable](slices ...[]T) []T
|
func SymmetricDifference[T comparable](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1CbOmtgILUU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2146,7 +2146,7 @@ func main() {
|
|||||||
func ToSlice[T any](items ...T) []T
|
func ToSlice[T any](items ...T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/YzbzVq5kscN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2174,7 +2174,7 @@ func main() {
|
|||||||
func ToSlicePointer[T any](items ...T) []*T
|
func ToSlicePointer[T any](items ...T) []*T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/gx4tr6_VXSF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2209,7 +2209,7 @@ func main() {
|
|||||||
func Unique[T comparable](slice []T) []T
|
func Unique[T comparable](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/AXw0R3ZTE6a)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2236,7 +2236,7 @@ func main() {
|
|||||||
func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
|
func UniqueBy[T comparable](slice []T, iteratee func(item T) T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/UR323iZLDpv)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2267,7 +2267,7 @@ func main() {
|
|||||||
func Union[T comparable](slices ...[]T) []T
|
func Union[T comparable](slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/hfXV1iRIZOf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2298,7 +2298,7 @@ func main() {
|
|||||||
func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
|
func UnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/HGKHfxKQsFi)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2323,7 +2323,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="UpdateAt">UpdateAt</span>
|
### <span id="UpdateAt">UpdateAt</span>
|
||||||
|
|
||||||
<p>Update the slice element at index. if param index < 0 or index >= len(slice), will return error. </p>
|
<p>Update the slice element at index. if param index < 0 or index <= len(slice), will return error. </p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -2331,7 +2331,7 @@ func main() {
|
|||||||
func UpdateAt[T any](slice []T, index int, value T) []T
|
func UpdateAt[T any](slice []T, index int, value T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/f3mh2KloWVm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2363,7 +2363,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="Without">Without</span>
|
### <span id="Without">Without</span>
|
||||||
|
|
||||||
<p>Creates a slice excluding all given items. </p>
|
<p>Creates a slice excluding all given items.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -2371,7 +2371,7 @@ func main() {
|
|||||||
func Without[T comparable](slice []T, items ...T) []T
|
func Without[T comparable](slice []T, items ...T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/bwhEXEypThg)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2399,7 +2399,7 @@ func main() {
|
|||||||
func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
|
func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uXod2LWD1Kg)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2429,7 +2429,7 @@ func main() {
|
|||||||
func Join[T any](s []T, separator string) string
|
func Join[T any](s []T, separator string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/huKzqwNDD7V)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2451,3 +2451,39 @@ func main() {
|
|||||||
// 1-2-3-4-5
|
// 1-2-3-4-5
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="Partition">Partition</span>
|
||||||
|
|
||||||
|
<p>Partition all slice elements with the evaluation of the given predicate functions. </p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Partition[T any](slice []T, predicates ...func(item T) bool) [][]T
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/lkQ3Ri2NQhV)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
nums := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
|
result1 := slice.Partition(nums)
|
||||||
|
result2 := slice.Partition(nums, func(n int) bool { return n%2 == 0 })
|
||||||
|
result3 := slice.Partition(nums, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 })
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// [[1 2 3 4 5]]
|
||||||
|
// [[2 4] [1 3 5]]
|
||||||
|
// [[1 2] [3 4] [5]]
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -51,6 +51,7 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="Of">Of</span>
|
### <span id="Of">Of</span>
|
||||||
@@ -63,7 +64,7 @@ import (
|
|||||||
func Of[T any](elems ...T) stream[T]
|
func Of[T any](elems ...T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jI6_iZZuVFE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -93,7 +94,7 @@ func main() {
|
|||||||
func FromSlice[T any](source []T) stream[T]
|
func FromSlice[T any](source []T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/wywTO0XZtI4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -123,7 +124,7 @@ func main() {
|
|||||||
func FromChannel[T any](source <-chan T) stream[T]
|
func FromChannel[T any](source <-chan T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9TZYugGMhXZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -161,7 +162,7 @@ func main() {
|
|||||||
func FromRange[T constraints.Integer | constraints.Float](start, end, step T) stream[T]
|
func FromRange[T constraints.Integer | constraints.Float](start, end, step T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9Ex1-zcg-B-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -190,7 +191,7 @@ func main() {
|
|||||||
func Generate[T any](generator func() func() (item T, ok bool)) stream[T]
|
func Generate[T any](generator func() func() (item T, ok bool)) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/rkOWL1yA3j9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -230,7 +231,7 @@ func main() {
|
|||||||
func Concat[T any](a, b stream[T]) stream[T]
|
func Concat[T any](a, b stream[T]) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/HM4OlYk_OUC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -263,7 +264,7 @@ func main() {
|
|||||||
func (s stream[T]) Distinct() stream[T]
|
func (s stream[T]) Distinct() stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/eGkOSrm64cB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -297,7 +298,7 @@ func main() {
|
|||||||
func (s stream[T]) Filter(predicate func(item T) bool) stream[T]
|
func (s stream[T]) Filter(predicate func(item T) bool) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/MFlSANo-buc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -331,7 +332,7 @@ func main() {
|
|||||||
func (s stream[T]) Map(mapper func(item T) T) stream[T]
|
func (s stream[T]) Map(mapper func(item T) T) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/OtNQUImdYko)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -365,7 +366,7 @@ func main() {
|
|||||||
func (s stream[T]) Peek(consumer func(item T)) stream[T]
|
func (s stream[T]) Peek(consumer func(item T)) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/u1VNzHs6cb2)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -402,7 +403,7 @@ func main() {
|
|||||||
func (s stream[T]) Skip(n int) stream[T]
|
func (s stream[T]) Skip(n int) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fNdHbqjahum)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -441,7 +442,7 @@ func main() {
|
|||||||
func (s stream[T]) Limit(maxSize int) stream[T]
|
func (s stream[T]) Limit(maxSize int) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qsO4aniDcGf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -480,7 +481,7 @@ func main() {
|
|||||||
func (s stream[T]) Reverse() stream[T]
|
func (s stream[T]) Reverse() stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/A8_zkJnLHm4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -510,7 +511,7 @@ func main() {
|
|||||||
func (s stream[T]) Range(start, end int) stream[T]
|
func (s stream[T]) Range(start, end int) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/indZY5V2f4j)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -549,7 +550,7 @@ func main() {
|
|||||||
func (s stream[T]) Sorted(less func(a, b T) bool) stream[T]
|
func (s stream[T]) Sorted(less func(a, b T) bool) stream[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/XXtng5uonFj)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -581,7 +582,7 @@ func main() {
|
|||||||
func (s stream[T]) ForEach(action func(item T))
|
func (s stream[T]) ForEach(action func(item T))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Dsm0fPqcidk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -614,7 +615,7 @@ func main() {
|
|||||||
func (s stream[T]) Reduce(initial T, accumulator func(a, b T) T) T
|
func (s stream[T]) Reduce(initial T, accumulator func(a, b T) T) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/6uzZjq_DJLU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -646,7 +647,7 @@ func main() {
|
|||||||
func (s stream[T]) FindFirst() (T, bool)
|
func (s stream[T]) FindFirst() (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9xEf0-6C1e3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -678,7 +679,7 @@ func main() {
|
|||||||
func (s stream[T]) FindLast() (T, bool)
|
func (s stream[T]) FindLast() (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/WZD2rDAW-2h)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -710,7 +711,7 @@ func main() {
|
|||||||
func (s stream[T]) Max(less func(a, b T) bool) (T, bool)
|
func (s stream[T]) Max(less func(a, b T) bool) (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/fm-1KOPtGzn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -734,7 +735,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="Min">Min</span>
|
### <span id="Min">Min</span>
|
||||||
|
|
||||||
<p>Returns the minimum element of this stream according to the provided less function. less fuction: a < b</p>
|
<p>Returns the minimum element of this stream according to the provided less function. less fuction: a < b</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -742,7 +743,7 @@ func main() {
|
|||||||
func (s stream[T]) Min(less func(a, b T) bool) (T, bool)
|
func (s stream[T]) Min(less func(a, b T) bool) (T, bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/vZfIDgGNRe_0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -774,7 +775,7 @@ func main() {
|
|||||||
func (s stream[T]) AllMatch(predicate func(item T) bool) bool
|
func (s stream[T]) AllMatch(predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/V5TBpVRs-Cx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -812,7 +813,7 @@ func main() {
|
|||||||
func (s stream[T]) AnyMatch(predicate func(item T) bool) bool
|
func (s stream[T]) AnyMatch(predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/PTCnWn4OxSn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -850,7 +851,7 @@ func main() {
|
|||||||
func (s stream[T]) NoneMatch(predicate func(item T) bool) bool
|
func (s stream[T]) NoneMatch(predicate func(item T) bool) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/iWS64pL1oo3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -888,7 +889,7 @@ func main() {
|
|||||||
func (s stream[T]) Count() int
|
func (s stream[T]) Count() int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/r3koY6y_Xo-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -919,7 +920,7 @@ func main() {
|
|||||||
func (s stream[T]) ToSlice() []T
|
func (s stream[T]) ToSlice() []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/jI6_iZZuVFE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
# Field
|
# Structs
|
||||||
|
|
||||||
Field is abstract struct field for provide several high level functions
|
Struct is abstract struct for provide several high level functions
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Source:
|
## Source:
|
||||||
|
|
||||||
|
- [https://github.com/duke-git/lancet/blob/main/structs/struct.go](https://github.com/duke-git/lancet/blob/main/structs/struct.go)
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/structs/field.go](https://github.com/duke-git/lancet/blob/main/structs/field.go)
|
- [https://github.com/duke-git/lancet/blob/main/structs/field.go](https://github.com/duke-git/lancet/blob/main/structs/field.go)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
@@ -22,6 +24,11 @@ import (
|
|||||||
|
|
||||||
## Index:
|
## Index:
|
||||||
|
|
||||||
|
- [New](#New)
|
||||||
|
- [ToMap](#ToMap)
|
||||||
|
- [Fields](#Fields)
|
||||||
|
- [Field](#Field)
|
||||||
|
- [IsStruct](#IsStruct)
|
||||||
- [Tag](#Tag)
|
- [Tag](#Tag)
|
||||||
- [Name](#Name)
|
- [Name](#Name)
|
||||||
- [Value](#Value)
|
- [Value](#Value)
|
||||||
@@ -31,17 +38,191 @@ import (
|
|||||||
- [IsZero](#IsZero)
|
- [IsZero](#IsZero)
|
||||||
- [IsSlice](#IsSlice)
|
- [IsSlice](#IsSlice)
|
||||||
|
|
||||||
> Note:Since `Field` inherits from `Struct`, it also has all the methods of 'Struct', as follows:
|
|
||||||
|
|
||||||
- [ToMap](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#ToMap)
|
|
||||||
- [Fields](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#Fields)
|
|
||||||
- [Field](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#Field)
|
|
||||||
- [IsStruct](https://github.com/duke-git/lancet/blob/main/docs/structs/struct.md#IsStruct)
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## Documentation:
|
## Documentation:
|
||||||
|
|
||||||
|
### <span id="New">New</span>
|
||||||
|
|
||||||
|
<p>The constructor function of the `Struct` </p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func New(value any, tagName ...string) *Struct
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
// to do something
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="ToMap">ToMap</span>
|
||||||
|
|
||||||
|
<p>convert a valid struct to a map</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) ToMap() (map[string]any, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
> In addition, provided a convenient static function ToMap
|
||||||
|
|
||||||
|
```go
|
||||||
|
func ToMap(v any) (map[string]any, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
// use constructor function
|
||||||
|
s1 := structs.New(p1)
|
||||||
|
m1, _ := s1.ToMap()
|
||||||
|
|
||||||
|
fmt.Println(m1)
|
||||||
|
|
||||||
|
// use static function
|
||||||
|
m2, _ := structs.ToMap(p1)
|
||||||
|
|
||||||
|
fmt.Println(m2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// map[name:11]
|
||||||
|
// map[name:11]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Fields">Fields</span>
|
||||||
|
|
||||||
|
<p>Get all fields of a given struct, that the fields are abstract struct field</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) Fields() []*Field
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
fields := s.Fields()
|
||||||
|
|
||||||
|
fmt.Println(len(fields))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Field">Field</span>
|
||||||
|
|
||||||
|
<p>Get an abstract field of a struct by given field name </p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) Field(name string) *Field
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
f := s.Field("Name")
|
||||||
|
|
||||||
|
fmt.Println(f.Value())
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 11
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsStruct">IsStruct</span>
|
||||||
|
|
||||||
|
<p>Check if the struct is valid</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (s *Struct) IsStruct() bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
type People struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
p1 := &People{Name: "11"}
|
||||||
|
s := structs.New(p1)
|
||||||
|
|
||||||
|
fmt.Println(s.IsStruct())
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### <span id="Tag">Tag</span>
|
### <span id="Tag">Tag</span>
|
||||||
|
|
||||||
<p>Get a `Tag` of the `Field`, `Tag` is a abstract struct field tag</p>
|
<p>Get a `Tag` of the `Field`, `Tag` is a abstract struct field tag</p>
|
||||||
@@ -49,6 +49,7 @@ import (
|
|||||||
- [StringToBytes](#StringToBytes)
|
- [StringToBytes](#StringToBytes)
|
||||||
- [BytesToString](#BytesToString)
|
- [BytesToString](#BytesToString)
|
||||||
- [IsBlank](#IsBlank)
|
- [IsBlank](#IsBlank)
|
||||||
|
- [IsNotBlank](#IsNotBlank)
|
||||||
- [HasPrefixAny](#HasPrefixAny)
|
- [HasPrefixAny](#HasPrefixAny)
|
||||||
- [HasSuffixAny](#HasSuffixAny)
|
- [HasSuffixAny](#HasSuffixAny)
|
||||||
- [IndexOffset](#IndexOffset)
|
- [IndexOffset](#IndexOffset)
|
||||||
@@ -74,7 +75,7 @@ import (
|
|||||||
func After(s, char string) string
|
func After(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/RbCOQqCDA7m)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -114,7 +115,7 @@ func main() {
|
|||||||
func AfterLast(s, char string) string
|
func AfterLast(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1TegARrb8Yn)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -154,7 +155,7 @@ func main() {
|
|||||||
func Before(s, char string) string
|
func Before(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/JAWTZDS4F5w)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -191,7 +192,7 @@ func main() {
|
|||||||
func BeforeLast(s, char string) string
|
func BeforeLast(s, char string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pJfXXAoG_Te)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -228,7 +229,7 @@ func main() {
|
|||||||
func CamelCase(s string) string
|
func CamelCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9eXP3tn2tUy)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -263,7 +264,7 @@ func main() {
|
|||||||
func KebabCase(s string) string
|
func KebabCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/dcZM9Oahw-Y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -298,7 +299,7 @@ func main() {
|
|||||||
func UpperKebabCase(s string) string
|
func UpperKebabCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/zDyKNneyQXk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -333,7 +334,7 @@ func main() {
|
|||||||
func Capitalize(s string) string
|
func Capitalize(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/2OAjgbmAqHZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -368,7 +369,7 @@ func main() {
|
|||||||
func IsString(v any) bool
|
func IsString(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/IOgq7oF9ERm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -408,7 +409,7 @@ func main() {
|
|||||||
func LowerFirst(s string) string
|
func LowerFirst(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/CbzAyZmtJwL)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -442,7 +443,7 @@ func main() {
|
|||||||
func UpperFirst(s string) string
|
func UpperFirst(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/sBbBxRbs8MM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -476,7 +477,7 @@ func main() {
|
|||||||
func Pad(source string, size int, padStr string) string
|
func Pad(source string, size int, padStr string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/NzImQq-VF8q)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -521,7 +522,7 @@ func main() {
|
|||||||
func PadEnd(source string, size int, padStr string) string
|
func PadEnd(source string, size int, padStr string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/9xP8rN0vz--)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -567,7 +568,7 @@ func main() {
|
|||||||
func PadStart(source string, size int, padStr string) string
|
func PadStart(source string, size int, padStr string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/xpTfzArDfvT)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -613,7 +614,7 @@ func main() {
|
|||||||
func Reverse(s string) string
|
func Reverse(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/adfwalJiecD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -644,7 +645,7 @@ func main() {
|
|||||||
func SnakeCase(s string) string
|
func SnakeCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/tgzQG11qBuN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -671,15 +672,15 @@ func main() {
|
|||||||
|
|
||||||
### <span id="UpperSnakeCase">UpperSnakeCase</span>
|
### <span id="UpperSnakeCase">UpperSnakeCase</span>
|
||||||
|
|
||||||
<p>Coverts string to upper KEBAB-CASE, non letters and numbers will be ignored.</p>
|
<p>Coverts string to upper snake_case, non letters and numbers will be ignored.</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func SnakeCase(s string) string
|
func UpperSnakeCase(s string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/4COPHpnLx38)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -714,7 +715,7 @@ func main() {
|
|||||||
func SplitEx(s, sep string, removeEmptyString bool) []string
|
func SplitEx(s, sep string, removeEmptyString bool) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Us-ySSbWh-3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -755,7 +756,7 @@ func main() {
|
|||||||
func Substring(s string, offset int, length uint) string
|
func Substring(s string, offset int, length uint) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/q3sM6ehnPDp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -798,7 +799,7 @@ func main() {
|
|||||||
func Wrap(str string, wrapWith string) string
|
func Wrap(str string, wrapWith string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KoZOlZDDt9y)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -825,7 +826,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="Wrap">Wrap</span>
|
### <span id="Unwrap">Unwrap</span>
|
||||||
|
|
||||||
<p>Unwrap a given string from anther string. will change source string.</p>
|
<p>Unwrap a given string from anther string. will change source string.</p>
|
||||||
|
|
||||||
@@ -835,7 +836,7 @@ func main() {
|
|||||||
func Unwrap(str string, wrapToken string) string
|
func Unwrap(str string, wrapToken string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Ec2q4BzCpG-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -875,7 +876,7 @@ func main() {
|
|||||||
func SplitWords(s string) []string
|
func SplitWords(s string) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KLiX4WiysMM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -918,7 +919,7 @@ func main() {
|
|||||||
func WordCount(s string) int
|
func WordCount(s string) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/bj7_odx3vRf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -961,7 +962,7 @@ func main() {
|
|||||||
func RemoveNonPrintable(str string) string
|
func RemoveNonPrintable(str string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/og47F5x_jTZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -992,7 +993,7 @@ func main() {
|
|||||||
func StringToBytes(str string) (b []byte)
|
func StringToBytes(str string) (b []byte)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/7OyFBrf9AxA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1023,7 +1024,7 @@ func main() {
|
|||||||
func BytesToString(bytes []byte) string
|
func BytesToString(bytes []byte) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/6c68HRvJecH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1052,7 +1053,7 @@ func main() {
|
|||||||
func IsBlank(str string) bool
|
func IsBlank(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/6zXRH_c0Qd3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1076,6 +1077,45 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="IsNotBlank">IsNotBlank</span>
|
||||||
|
|
||||||
|
<p>Checks if a string is not whitespace or not empty.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsNotBlank(str string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/strutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := IsNotBlank("")
|
||||||
|
result2 := IsNotBlank(" ")
|
||||||
|
result3 := IsNotBlank("\t\v\f\n")
|
||||||
|
result4 := IsNotBlank(" 中文")
|
||||||
|
result5 := IsNotBlank(" world ")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
fmt.Println(result5)
|
||||||
|
// Output:
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### <span id="HasPrefixAny">HasPrefixAny</span>
|
### <span id="HasPrefixAny">HasPrefixAny</span>
|
||||||
|
|
||||||
<p>Checks if a string starts with any of an array of specified strings.</p>
|
<p>Checks if a string starts with any of an array of specified strings.</p>
|
||||||
@@ -1083,10 +1123,10 @@ func main() {
|
|||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func ReplaceWithMap(str string, replaces map[string]string) string
|
func HasPrefixAny(str string, prefixes []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/8UUTl2C5slo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1117,7 +1157,7 @@ func main() {
|
|||||||
func HasSuffixAny(str string, suffixes []string) bool
|
func HasSuffixAny(str string, suffixes []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/sKWpCQdOVkx)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1148,7 +1188,7 @@ func main() {
|
|||||||
func IndexOffset(str string, substr string, idxFrom int) int
|
func IndexOffset(str string, substr string, idxFrom int) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/qZo4lV2fomB)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1190,7 +1230,7 @@ func main() {
|
|||||||
func ReplaceWithMap(str string, replaces map[string]string) string
|
func ReplaceWithMap(str string, replaces map[string]string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/h3t7CNj2Vvu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1223,7 +1263,7 @@ func main() {
|
|||||||
func Trim(str string, characterMask ...string) string
|
func Trim(str string, characterMask ...string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Y0ilP0NRV3j)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1260,7 +1300,7 @@ func main() {
|
|||||||
func SplitAndTrim(str, delimiter string, characterMask ...string) []string
|
func SplitAndTrim(str, delimiter string, characterMask ...string) []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ZNL6o4SkYQ7)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1293,7 +1333,7 @@ func main() {
|
|||||||
func HideString(origin string, start, end int, replaceChar string) string
|
func HideString(origin string, start, end int, replaceChar string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/pzbaIVCTreZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1332,7 +1372,7 @@ func main() {
|
|||||||
func ContainsAll(str string, substrs []string) bool
|
func ContainsAll(str string, substrs []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KECtK2Os4zq)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1365,7 +1405,7 @@ func main() {
|
|||||||
func ContainsAny(str string, substrs []string) bool
|
func ContainsAny(str string, substrs []string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/dZGSSMB3LXE)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1401,7 +1441,7 @@ func main() {
|
|||||||
func RemoveWhiteSpace(str string, repalceAll bool) string
|
func RemoveWhiteSpace(str string, repalceAll bool) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/HzLC9vsTwkf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -34,6 +34,7 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="IsWindows">IsWindows</span>
|
### <span id="IsWindows">IsWindows</span>
|
||||||
@@ -46,7 +47,7 @@ import (
|
|||||||
func IsWindows() bool
|
func IsWindows() bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/zIflQgZNuxD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -70,7 +71,7 @@ func main() {
|
|||||||
func IsLinux() bool
|
func IsLinux() bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/zIflQgZNuxD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -94,7 +95,7 @@ func main() {
|
|||||||
func IsMac() bool
|
func IsMac() bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Mg4Hjtyq7Zc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -118,7 +119,7 @@ func main() {
|
|||||||
func GetOsEnv(key string) string
|
func GetOsEnv(key string) string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/D88OYVCyjO-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -148,7 +149,7 @@ func main() {
|
|||||||
func SetOsEnv(key, value string) error
|
func SetOsEnv(key, value string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/D88OYVCyjO-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -178,7 +179,7 @@ func main() {
|
|||||||
func RemoveOsEnv(key string) error
|
func RemoveOsEnv(key string) error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/fqyq4b3xUFQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -216,7 +217,7 @@ func main() {
|
|||||||
func CompareOsEnv(key, comparedEnv string) bool
|
func CompareOsEnv(key, comparedEnv string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/BciHrKYOHbp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -252,7 +253,7 @@ type (
|
|||||||
func ExecCommand(command string, opts ...Option) (stdout, stderr string, err error)
|
func ExecCommand(command string, opts ...Option) (stdout, stderr string, err error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/n-2fLyZef-4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -292,7 +293,7 @@ func main() {
|
|||||||
func GetOsBits() int
|
func GetOsBits() int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/ml-_XH3gJbW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -61,6 +61,7 @@ import (
|
|||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="Tuple2">Tuple2</span>
|
### <span id="Tuple2">Tuple2</span>
|
||||||
@@ -78,7 +79,7 @@ type Tuple2[A any, B any] struct {
|
|||||||
func NewTuple2[A any, B any](a A, b B) Tuple2[A, B]
|
func NewTuple2[A any, B any](a A, b B) Tuple2[A, B]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/3sHVqBQpLYN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -106,7 +107,7 @@ func main() {
|
|||||||
func (t Tuple2[A, B]) Unbox() (A, B)
|
func (t Tuple2[A, B]) Unbox() (A, B)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/0fD1qfCVwjm)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -135,7 +136,7 @@ func main() {
|
|||||||
func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B]
|
func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/4ncWJJ77Xio)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -163,7 +164,7 @@ func main() {
|
|||||||
func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B)
|
func Unzip2[A any, B any](tuples []Tuple2[A, B]) ([]A, []B)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/KBecr60feXb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -198,7 +199,7 @@ type Tuple3[A any, B any, C any] struct {
|
|||||||
func NewTuple3[A any, B any, C any](a A, b B c C) Tuple3[A, B, C]
|
func NewTuple3[A any, B any, C any](a A, b B c C) Tuple3[A, B, C]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/FtH2sdCLlCf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -226,7 +227,7 @@ func main() {
|
|||||||
func (t Tuple3[A, B, C]) Unbox() (A, B, C)
|
func (t Tuple3[A, B, C]) Unbox() (A, B, C)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/YojLy-id1BS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -255,7 +256,7 @@ func main() {
|
|||||||
func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C]
|
func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/97NgmsTILfu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -283,7 +284,7 @@ func main() {
|
|||||||
func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C)
|
func Unzip3[A any, B any, C any](tuples []Tuple3[A, B, C]) ([]A, []B, []C)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/bba4cpAa7KO)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -321,7 +322,7 @@ type Tuple4[A any, B any, C any, D any] struct {
|
|||||||
func NewTuple4[A any, B any, C any, D any](a A, b B, c C, d D) Tuple4[A, B, C, D]
|
func NewTuple4[A any, B any, C any, D any](a A, b B, c C, d D) Tuple4[A, B, C, D]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/D2EqDz096tk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -349,7 +350,7 @@ func main() {
|
|||||||
func (t Tuple4[A, B, C, D]) Unbox() (A, B, C, D)
|
func (t Tuple4[A, B, C, D]) Unbox() (A, B, C, D)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/ACj9YuACGgW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -378,7 +379,7 @@ func main() {
|
|||||||
func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D]
|
func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/PEmTYVK5hL4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -406,7 +407,7 @@ func main() {
|
|||||||
func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D)
|
func Unzip4[A any, B any, C any, D any](tuples []Tuple4[A, B, C, D]) ([]A, []B, []C, []D)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/rb8z4gyYSRN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -445,7 +446,7 @@ type Tuple5[A any, B any, C any, D any, E any] struct {
|
|||||||
func NewTuple5[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E) Tuple5[A, B, C, D, E]
|
func NewTuple5[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E) Tuple5[A, B, C, D, E]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/2WndmVxPg-r)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -473,7 +474,7 @@ func main() {
|
|||||||
func (t Tuple5[A, B, C, D, E]) Unbox() (A, B, C, D, E)
|
func (t Tuple5[A, B, C, D, E]) Unbox() (A, B, C, D, E)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/GyIyZHjCvoS)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -502,7 +503,7 @@ func main() {
|
|||||||
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E]
|
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/fCAAJLMfBIP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -530,7 +531,7 @@ func main() {
|
|||||||
func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E)
|
func Unzip5[A any, B any, C any, D any, E any](tuples []Tuple5[A, B, C, D, E]) ([]A, []B, []C, []D, []E)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/gyl6vKfhqPb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -570,7 +571,7 @@ type Tuple6[A any, B any, C any, D any, E any, F any] struct {
|
|||||||
func NewTuple6[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F]
|
func NewTuple6[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) Tuple6[A, B, C, D, E, F]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/VjqcCwEJZbs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -598,7 +599,7 @@ func main() {
|
|||||||
func (t Tuple6[A, B, C, D, E, F]) Unbox() (A, B, C, D, E, F)
|
func (t Tuple6[A, B, C, D, E, F]) Unbox() (A, B, C, D, E, F)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/FjIHV7lpxmW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -627,7 +628,7 @@ func main() {
|
|||||||
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F]
|
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/oWPrnUYuFHo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -655,7 +656,7 @@ func main() {
|
|||||||
func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F)
|
func Unzip6[A any, B any, C any, D any, E any, F any](tuples []Tuple6[A, B, C, D, E, F]) ([]A, []B, []C, []D, []E, []F)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/l41XFqCyh5E)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -696,7 +697,7 @@ type Tuple7[A any, B any, C any, D any, E any, F any, G any] struct {
|
|||||||
func NewTuple7[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G]
|
func NewTuple7[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) Tuple7[A, B, C, D, E, F, G]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/dzAgv_Ezub9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -724,7 +725,7 @@ func main() {
|
|||||||
func (t Tuple7[A, B, C, D, E, F, G]) Unbox() (A, B, C, D, E, F, G)
|
func (t Tuple7[A, B, C, D, E, F, G]) Unbox() (A, B, C, D, E, F, G)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/R9I8qeDk0zs)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -753,7 +754,7 @@ func main() {
|
|||||||
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G]
|
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/WUJuo897Egf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -781,7 +782,7 @@ func main() {
|
|||||||
func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G)
|
func Unzip7[A any, B any, C any, D any, E any, F any, G any](tuples []Tuple7[A, B, C, D, E, F, G]) ([]A, []B, []C, []D, []E, []F, []G)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/hws_P1Fr2j3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -823,7 +824,7 @@ type Tuple8[A any, B any, C any, D any, E any, F any, G any, H any] struct {
|
|||||||
func NewTuple8[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H]
|
func NewTuple8[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) Tuple8[A, B, C, D, E, F, G, H]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/YA9S0rz3dRz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -851,7 +852,7 @@ func main() {
|
|||||||
func (t Tuple8[A, B, C, D, E, F, G, H]) Unbox() (A, B, C, D, E, F, G, H)
|
func (t Tuple8[A, B, C, D, E, F, G, H]) Unbox() (A, B, C, D, E, F, G, H)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/PRxLBBb4SMl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -880,7 +881,7 @@ func main() {
|
|||||||
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H]
|
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/8V9jWkuJfaQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -908,7 +909,7 @@ func main() {
|
|||||||
func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H)
|
func Unzip8[A any, B any, C any, D any, E any, F any, G any, H any](tuples []Tuple8[A, B, C, D, E, F, G, H]) ([]A, []B, []C, []D, []E, []F, []G, []H)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/1SndOwGsZB4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -953,7 +954,7 @@ func NewTuple9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/yS2NGGtZpQr)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -981,7 +982,7 @@ func main() {
|
|||||||
func (t Tuple9[A, B, C, D, E, F, G, H, I]) Unbox() (A, B, C, D, E, F, G, H, I)
|
func (t Tuple9[A, B, C, D, E, F, G, H, I]) Unbox() (A, B, C, D, E, F, G, H, I)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/oFJFGTAuOa8)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1010,7 +1011,7 @@ func main() {
|
|||||||
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I]
|
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/cgsL15QYnfz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1038,7 +1039,7 @@ func main() {
|
|||||||
func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I)
|
func Unzip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tuples []Tuple9[A, B, C, D, E, F, G, H, I]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/91-BU_KURSA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1084,7 +1085,7 @@ func NewTuple10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/799qqZg0hUv)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1115,7 +1116,7 @@ func main() {
|
|||||||
func (t Tuple10[A, B, C, D, E, F, G, H, I, J]) Unbox() (A, B, C, D, E, F, G, H, I, J)
|
func (t Tuple10[A, B, C, D, E, F, G, H, I, J]) Unbox() (A, B, C, D, E, F, G, H, I, J)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/qfyx3x_X0Cu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1147,7 +1148,7 @@ func main() {
|
|||||||
func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I, j []J) []Tuple10[A, B, C, D, E, F, G, H, I, J]
|
func Zip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I, j []J) []Tuple10[A, B, C, D, E, F, G, H, I, J]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/YSR-2cXnrY4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1175,7 +1176,7 @@ func main() {
|
|||||||
func Unzip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](tuples []Tuple10[A, B, C, D, E, F, G, H, I, J]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I, []J)
|
func Unzip10[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](tuples []Tuple10[A, B, C, D, E, F, G, H, I, J]) ([]A, []B, []C, []D, []E, []F, []G, []H, []I, []J)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/-taQB6Wfre_z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -55,9 +55,20 @@ import (
|
|||||||
- [IsZeroValue](#IsZeroValue)
|
- [IsZeroValue](#IsZeroValue)
|
||||||
- [IsGBK](#IsGBK)
|
- [IsGBK](#IsGBK)
|
||||||
- [IsPrintable](#IsPrintable)
|
- [IsPrintable](#IsPrintable)
|
||||||
|
- [IsBin](#IsBin)
|
||||||
|
- [IsHex](#IsHex)
|
||||||
|
- [IsBase64URL](#IsBase64URL)
|
||||||
|
- [IsJWT](#IsJWT)
|
||||||
|
- [IsVisa](#IsVisa)
|
||||||
|
- [IsMasterCard](#IsMasterCard)
|
||||||
|
- [IsAmericanExpress](#IsAmericanExpress)
|
||||||
|
- [IsUnionPay](#IsUnionPay)
|
||||||
|
- [IsChinaUnionPay](#IsChinaUnionPay)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="/styles/api_doc.css">
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
### <span id="ContainChinese">ContainChinese</span>
|
### <span id="ContainChinese">ContainChinese</span>
|
||||||
@@ -70,7 +81,7 @@ import (
|
|||||||
func ContainChinese(s string) bool
|
func ContainChinese(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/7DpU0uElYeM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -104,7 +115,7 @@ func main() {
|
|||||||
func ContainLetter(str string) bool
|
func ContainLetter(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/lqFD04Yyewp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -138,7 +149,7 @@ func main() {
|
|||||||
func ContainLower(str string) bool
|
func ContainLower(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Srqi1ItvnAA)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -172,7 +183,7 @@ func main() {
|
|||||||
func ContainUpper(str string) bool
|
func ContainUpper(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/CmWeBEk27-z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -206,7 +217,7 @@ func main() {
|
|||||||
func IsAlpha(s string) bool
|
func IsAlpha(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/7Q5sGOz2izQ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -240,7 +251,7 @@ func main() {
|
|||||||
func IsAllUpper(str string) bool
|
func IsAllUpper(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/ZHctgeK1n4Z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -274,7 +285,7 @@ func main() {
|
|||||||
func IsAllLower(str string) bool
|
func IsAllLower(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/GjqCnOfV6cM)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -308,7 +319,7 @@ func main() {
|
|||||||
func IsASCII(str string) bool
|
func IsASCII(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/hfQNPLX0jNa)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -348,7 +359,7 @@ func main() {
|
|||||||
func IsBase64(base64 string) bool
|
func IsBase64(base64 string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/sWHEySAt6hl)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -379,7 +390,7 @@ func main() {
|
|||||||
func IsChineseMobile(mobileNum string) bool
|
func IsChineseMobile(mobileNum string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/GPYUlGTOqe3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -410,7 +421,7 @@ func main() {
|
|||||||
func IsChineseIdNum(id string) bool
|
func IsChineseIdNum(id string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/d8EWhl2UGDF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -441,7 +452,7 @@ func main() {
|
|||||||
func IsChinesePhone(phone string) bool
|
func IsChinesePhone(phone string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/RUD_-7YZJ3I)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -472,7 +483,7 @@ func main() {
|
|||||||
func IsCreditCard(creditCart string) bool
|
func IsCreditCard(creditCart string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/sNwwL6B0-v4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -503,7 +514,7 @@ func main() {
|
|||||||
func IsDns(dns string) bool
|
func IsDns(dns string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/jlYApVLLGTZ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -537,7 +548,7 @@ func main() {
|
|||||||
func IsEmail(email string) bool
|
func IsEmail(email string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Os9VaFlT33G)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -568,7 +579,7 @@ func main() {
|
|||||||
func IsEmptyString(s string) bool
|
func IsEmptyString(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/dpzgUjFnBCX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -602,7 +613,7 @@ func main() {
|
|||||||
func IsInt(v any) bool
|
func IsInt(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/eFoIHbgzl-z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -639,7 +650,7 @@ func main() {
|
|||||||
func IsFloat(v any) bool
|
func IsFloat(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/vsyG-sxr99_Z)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -676,7 +687,7 @@ func main() {
|
|||||||
func IsNumber(v any) bool
|
func IsNumber(v any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/mdJHOAvtsvF)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -713,7 +724,7 @@ func main() {
|
|||||||
func IsIntStr(s string) bool
|
func IsIntStr(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/jQRtFv-a0Rk)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -750,7 +761,7 @@ func main() {
|
|||||||
func IsFloatStr(s string) bool
|
func IsFloatStr(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/LOYwS_Oyl7U)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -787,7 +798,7 @@ func main() {
|
|||||||
func IsNumberStr(s string) bool
|
func IsNumberStr(s string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/LzaKocSV79u)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -824,7 +835,7 @@ func main() {
|
|||||||
func IsJSON(str string) bool
|
func IsJSON(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/8Kip1Itjiil)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -861,7 +872,7 @@ func main() {
|
|||||||
func IsRegexMatch(s, regex string) bool
|
func IsRegexMatch(s, regex string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/z_XeZo_litG)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -892,7 +903,7 @@ func main() {
|
|||||||
func IsIp(ipstr string) bool
|
func IsIp(ipstr string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/FgcplDvmxoD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -929,7 +940,7 @@ func main() {
|
|||||||
func IsIpV4(ipstr string) bool
|
func IsIpV4(ipstr string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/zBGT99EjaIu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -960,7 +971,7 @@ func main() {
|
|||||||
func IsIpV6(ipstr string) bool
|
func IsIpV6(ipstr string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/AHA0r0AzIdC)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -983,7 +994,7 @@ func main() {
|
|||||||
|
|
||||||
### <span id="IsStrongPassword">IsStrongPassword</span>
|
### <span id="IsStrongPassword">IsStrongPassword</span>
|
||||||
|
|
||||||
<p>Check if the string is strong password (alpha(lower+upper) + number + special chars(!@#$%^&*()?><)).</p>
|
<p>Check if the string is strong password (alpha(lower+upper) + number + special chars(!@#$%^&*()?gt<)).</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
@@ -991,7 +1002,7 @@ func main() {
|
|||||||
func IsStrongPassword(password string, length int) bool
|
func IsStrongPassword(password string, length int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/QHdVcSQ3uDg)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1022,7 +1033,7 @@ func main() {
|
|||||||
func IsUrl(str string) bool
|
func IsUrl(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/pbJGa7F98Ka)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1057,7 +1068,7 @@ func main() {
|
|||||||
func IsWeakPassword(password string, length int) bool
|
func IsWeakPassword(password string, length int) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/wqakscZH5gH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1088,7 +1099,7 @@ func main() {
|
|||||||
func IsZeroValue(value any) bool
|
func IsZeroValue(value any) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/UMrwaDCi_t4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1125,7 +1136,7 @@ func main() {
|
|||||||
func IsGBK(data []byte) bool
|
func IsGBK(data []byte) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/E2nt3unlmzP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1157,7 +1168,7 @@ func main() {
|
|||||||
func IsPrintable(str string) bool
|
func IsPrintable(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Pe1FE2gdtTP)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1186,3 +1197,300 @@ func main() {
|
|||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="IsBin">IsBin</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid binary value or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsBin(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/ogPeg2XJH4P)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsBin("0101")
|
||||||
|
result2 := validator.IsBin("0b1101")
|
||||||
|
result3 := validator.IsBin("b1101")
|
||||||
|
result4 := validator.IsBin("1201")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsHex">IsHex</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid hexadecimal value or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsHex(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/M2qpHbEwmm7)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsHex("0xabcde")
|
||||||
|
result2 := validator.IsHex("0XABCDE")
|
||||||
|
result3 := validator.IsHex("cdfeg")
|
||||||
|
result4 := validator.IsHex("0xcdfeg")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsBase64URL">IsBase64URL</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid URL-safe Base64 encoded string.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsBase64URL(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/vhl4mr8GZ6S)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ")
|
||||||
|
result2 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ==")
|
||||||
|
result3 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ=")
|
||||||
|
result4 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ===")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsJWT">IsJWT</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is is a valid JSON Web Token (JWT).</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsJWT(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/R6Op7heJbKI)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibWVzc2FnZSI6IlB1dGluIGlzIGFic29sdXRlIHNoaXQiLCJpYXQiOjE1MTYyMzkwMjJ9.wkLWA5GtCpWdxNOrRse8yHZgORDgf8TpJp73WUQb910")
|
||||||
|
result2 := validator.IsJWT("abc")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsVisa">IsVisa</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid visa card nubmer or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsVisa(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/SdS2keOyJsl)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsVisa("4111111111111111")
|
||||||
|
result2 := validator.IsVisa("123")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsMasterCard">IsMasterCard</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid mastercard nubmer or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsMasterCard(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/CwWBFRrG27b)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsMasterCard("5425233430109903")
|
||||||
|
result2 := validator.IsMasterCard("4111111111111111")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsAmericanExpress">IsAmericanExpress</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid american express nubmer or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsAmericanExpress(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/HIDFpcOdpkd)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsAmericanExpress("342883359122187")
|
||||||
|
result2 := validator.IsAmericanExpress("3782822463100007")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsUnionPay">IsVisa</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid union pay nubmer or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsUnionPay(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/CUHPEwEITDf)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsUnionPay("6221263430109903")
|
||||||
|
result2 := validator.IsUnionPay("3782822463100007")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="IsChinaUnionPay">IsChinaUnionPay</span>
|
||||||
|
|
||||||
|
<p>Checks if a give string is a valid china union pay nubmer or not.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func IsChinaUnionPay(v string) bool
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/yafpdxLiymu)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := validator.IsChinaUnionPay("6250941006528599")
|
||||||
|
result2 := validator.IsChinaUnionPay("3782822463100007")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -58,7 +58,7 @@ type XError struct {
|
|||||||
func New(format string, args ...any) *XError
|
func New(format string, args ...any) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/w4oWZts7q7f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -87,7 +87,7 @@ func main() {
|
|||||||
func Wrap(cause error, message ...any) *XError
|
func Wrap(cause error, message ...any) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/5385qT2dCi4)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -118,7 +118,7 @@ func main() {
|
|||||||
func Unwrap(err error) *XError
|
func Unwrap(err error) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/LKMLep723tu)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -153,24 +153,25 @@ func main() {
|
|||||||
func (e *XError) Wrap(cause error) *XError
|
func (e *XError) Wrap(cause error) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/RpjJ5u5sc97)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"errors"
|
||||||
"github.com/duke-git/lancet/v2/xerror"
|
"github.com/duke-git/lancet/v2/xerror"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := xerror.New("wrong password")
|
err1 := xerror.New("error").With("level", "high")
|
||||||
wrapErr := xerror.Wrap(err, "error")
|
err2 := err1.Wrap(errors.New("invalid username"))
|
||||||
|
|
||||||
fmt.Println(wrapErr.Error())
|
fmt.Println(err2.Error())
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// error: wrong password
|
// error: invalid username
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -184,7 +185,7 @@ func main() {
|
|||||||
func (e *XError) Unwrap() error
|
func (e *XError) Unwrap() error
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/VUXJ8BST4c6)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -217,7 +218,7 @@ func main() {
|
|||||||
func (e *XError) With(key string, value any) *XError
|
func (e *XError) With(key string, value any) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ow8UISXX_Dp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -249,7 +250,7 @@ func main() {
|
|||||||
func (e *XError) Id(id string) *XError
|
func (e *XError) Id(id string) *XError
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/X6HBlsy58U9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -286,7 +287,7 @@ func main() {
|
|||||||
func (e *XError) Is(target error) bool
|
func (e *XError) Is(target error) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/X6HBlsy58U9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -323,7 +324,7 @@ func main() {
|
|||||||
func (e *XError) Values() map[string]any
|
func (e *XError) Values() map[string]any
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/ow8UISXX_Dp)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -356,7 +357,7 @@ func main() {
|
|||||||
func (e *XError) StackTrace() StackTrace
|
func (e *XError) StackTrace() StackTrace
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/6FAvSQpa7pc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -390,7 +391,7 @@ func main() {
|
|||||||
func (e *XError) Info() *errInfo
|
func (e *XError) Info() *errInfo
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/1ZX0ME1F-Jb)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -430,7 +431,7 @@ func main() {
|
|||||||
func (e *XError) Error() string
|
func (e *XError) Error() string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/w4oWZts7q7f)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -458,7 +459,7 @@ func main() {
|
|||||||
func TryUnwrap[T any](val T, err error) T
|
func TryUnwrap[T any](val T, err error) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:</b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/acyZVkNZEeW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
37
docs/en/guide/contribution_guide.md
Normal file
37
docs/en/guide/contribution_guide.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Lancet Contribution Guide
|
||||||
|
|
||||||
|
Hi! Thank you for choosing Lancet.
|
||||||
|
|
||||||
|
Lancet is a powerful, efficient, and reusable util function library of go. It makes Go dev easier by taking the hassle out of working with concurrency, net, math, slice, string, etc.
|
||||||
|
|
||||||
|
We are excited that you are interested in contributing to lancet. Before submitting your contribution though, please make sure to take a moment and read through the following guidelines.
|
||||||
|
|
||||||
|
## Issue Guidelines
|
||||||
|
|
||||||
|
- Issues are exclusively for bug reports, feature requests and design-related topics. Other questions may be closed directly.
|
||||||
|
|
||||||
|
- Before submitting an issue, please check if similar problems have already been issued.
|
||||||
|
|
||||||
|
- Please specify which version of Lancet and Go you are using, and provide OS information. [Go Playground](https://go.dev/play/) is recommended to build a live demo so that your issue can be reproduced clearly.
|
||||||
|
|
||||||
|
## Pull Request Guidelines
|
||||||
|
|
||||||
|
- Fork this repository to your own account. Do not create branches here.
|
||||||
|
|
||||||
|
- Commit info should be formatted as `type(scope): info about commit`. eg. `fix(package): [scrollbar] fix xxx bug`.
|
||||||
|
|
||||||
|
1. type: type must be one of [chore, docs, feat, fix, refactor, release, test].
|
||||||
|
|
||||||
|
2. scope: scope must be one of [package, file, internal].
|
||||||
|
|
||||||
|
3. header: header must not be longer than 72 characters.
|
||||||
|
|
||||||
|
- Rebase before creating a PR to keep commit history clear.
|
||||||
|
|
||||||
|
- Before submitting a PR, please execute the unit test command: `go test -v ./...` to ensure that all unit test tasks should pass.
|
||||||
|
|
||||||
|
- Make sure PRs are created to `v2` branch instead of `master` branch.
|
||||||
|
|
||||||
|
- If your PR fixes a bug, please provide a description about the related bug.
|
||||||
|
|
||||||
|
- If the PR is for a new feature, make sure to complete the relevant documentation (/lancet/docs/en/api/packages).
|
||||||
6
docs/en/guide/contributors.md
Normal file
6
docs/en/guide/contributors.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Contributors
|
||||||
|
<b>Thank you to all the people who contributed to lancet!</b>
|
||||||
|
|
||||||
|
<a href="https://github.com/duke-git/lancet/graphs/contributors">
|
||||||
|
<img src="https://contrib.rocks/image?repo=duke-git/lancet" />
|
||||||
|
</a>
|
||||||
@@ -47,4 +47,4 @@ func main() {
|
|||||||
|
|
||||||
## More
|
## More
|
||||||
|
|
||||||
Check out the [APIs]([API](https://lancet.go.dev/api/overview.html)) for details.
|
Check out the [API](https://www.golancet.cn/en/api/overview.html) for details.
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ hero:
|
|||||||
- theme: alt
|
- theme: alt
|
||||||
text: View on GitHub
|
text: View on GitHub
|
||||||
link: https://github.com/duke-git/lancet
|
link: https://github.com/duke-git/lancet
|
||||||
# - theme: alt
|
|
||||||
# text: API Examples
|
|
||||||
# link: /api-examples
|
|
||||||
image:
|
image:
|
||||||
src: /lancet_logo.png
|
src: /lancet_logo.png
|
||||||
alt: lancet
|
alt: lancet
|
||||||
@@ -37,7 +35,19 @@ features:
|
|||||||
|
|
||||||
<p style="position:relative; top: -316px;left: 560px;">
|
<p style="position:relative; top: -316px;left: 560px;">
|
||||||
<img style="display: inline-block;margin-right:10px;" src="https://img.shields.io/github/stars/duke-git/lancet?style=social" alt="">
|
<img style="display: inline-block;margin-right:10px;" src="https://img.shields.io/github/stars/duke-git/lancet?style=social" alt="">
|
||||||
|
<img style="display: inline-block" src="https://img.shields.io/github/forks/duke-git/lancet?style=social" alt="">
|
||||||
|
</p>
|
||||||
|
|
||||||
<img style="display: inline-block" src="https://img.shields.io/github/forks/duke-git/lancet?style=social" alt="">
|
<a style="border-color: #4565d8;
|
||||||
|
color: #fff;
|
||||||
</p>
|
background-color: #4565d8;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 0 20px;
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
display: block;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 600;
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 200px;" href="/en/sponsor/sponsor.html">Become a sponsor</a>
|
||||||
41
docs/en/sponsor/sponsor.md
Normal file
41
docs/en/sponsor/sponsor.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
|
||||||
|
### Sponsor me
|
||||||
|
|
||||||
|
<b>Hello, I am a software developer and have been engaged in development work for 13 years. Love open source software. And be willing to put in the energy for it. I am the creator of project [lancet](https://github.com/duke-git/lancet). Since Lancet was released as open source two years ago, it has been used by more than 1,000 internal and external projects. lancet will always be free for all users. Your support is a powerful encouragement for me to continue my struggle. Thanks! You can use WeChat to scans the following QR code or clicks the following sponsor button to initiate sponsorship.</b>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.sponsor-ctn {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.sponsor-pay {
|
||||||
|
display: inline-block;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
.sponsor-btn {
|
||||||
|
border-color: #4565d8;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #4565d8;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 0 20px;
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
text-align: center;
|
||||||
|
width: 140px;
|
||||||
|
position: absolute;
|
||||||
|
left: 360px;
|
||||||
|
top: 120px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="sponsor-ctn">
|
||||||
|
<img src="/public/wechat_pay.png" width="260" height="260" class="sponsor-pay"/>
|
||||||
|
|
||||||
|
<a class="sponsor-btn" style="color: #fff;font-weight: 600;" href="https://en.liberapay.com/Duke_Du/donate" target="\_blank">Sponsor</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
*Donated funds will be used to maintain this website and pay for cloud server costs. Or just buy me a cup of ☕️ when I'm sleepy writing code.*
|
||||||
37
docs/guide/contribution_guide.md
Normal file
37
docs/guide/contribution_guide.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Lancet 贡献指南
|
||||||
|
|
||||||
|
Hi! 首先感谢你使用 Lancet。
|
||||||
|
|
||||||
|
lancet(柳叶刀)是一个功能强大、全面、高效、可复用的go语言工具函数库。它消除了处理并发、网络、数学、切片、字符串等的麻烦,使 Go 开发变得更容易。
|
||||||
|
|
||||||
|
Lancet 的成长离不开大家的支持,如果你愿意为 Lancet 贡献代码或提供建议,请阅读以下内容。
|
||||||
|
|
||||||
|
## Issue 规范
|
||||||
|
|
||||||
|
- issue 仅用于提交 Bug 或 Feature 以及设计相关的内容,其它内容可能会被直接关闭。
|
||||||
|
|
||||||
|
- 在提交 issue 之前,请搜索相关内容是否已被提出。
|
||||||
|
|
||||||
|
- 请说明 Lancet 和 Go 的版本号,并提供操作系统信息。推荐使用 [Go Playground](https://go.dev/play/) 生成在线 demo,这能够更直观地重现问题。
|
||||||
|
|
||||||
|
## Pull Request 规范
|
||||||
|
|
||||||
|
- 请先 fork 一份到自己的项目下,不要直接在仓库下建分支。
|
||||||
|
|
||||||
|
- commit 信息要以 `type(scope): 描述信息` 的形式填写,例如 `fix(package): [scrollbar] fix xxx bug`。
|
||||||
|
|
||||||
|
1. type: 必须是 chore, docs, feat, fix, refactor, release, test 其中的一个。
|
||||||
|
|
||||||
|
2. scope: 必须是 package, file, internal 其中的一个。
|
||||||
|
|
||||||
|
3. header: 描述信息不要超过 72 个字符。
|
||||||
|
|
||||||
|
- 提交 PR 前请 rebase,确保 commit 记录的整洁。
|
||||||
|
|
||||||
|
- 提交 PR 前请执行单元测试命令:go test -v ./...,确保所有单元测试任务通过。
|
||||||
|
|
||||||
|
- 确保 PR 是提交到 `v2` 分支,而不是 `main` 分支。
|
||||||
|
|
||||||
|
- 如果是修复 bug,请在 PR 中给出描述信息。
|
||||||
|
|
||||||
|
- 如果PR是新功能,确保完成相关文档(/lancet/docs/api/packages/)。
|
||||||
7
docs/guide/contributors.md
Normal file
7
docs/guide/contributors.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# 贡献者
|
||||||
|
|
||||||
|
<b>感谢所有为lancet贡献过代码的人!</b>
|
||||||
|
|
||||||
|
<a href="https://github.com/duke-git/lancet/graphs/contributors">
|
||||||
|
<img src="https://contrib.rocks/image?repo=duke-git/lancet" />
|
||||||
|
</a>
|
||||||
@@ -43,6 +43,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## More
|
## 更多
|
||||||
|
|
||||||
其他特性请参考[API](https://lancet.go.dev/api/overview.html).
|
更多特性请参考[API](https://www.golancet.cn/api/overview.html).
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ outline: deep
|
|||||||
|
|
||||||
# lancet是什么?
|
# lancet是什么?
|
||||||
|
|
||||||
<b>lancet(柳叶刀)是一个强大、全面、高效、可复用的go语言工具函数库。lancet受到了java apache common包和lodash.js的启发。 </b>
|
<b>lancet(柳叶刀)是一个功能强大、全面、高效、可复用的go语言工具函数库。lancet受到了java apache common包和lodash.js的启发。 </b>
|
||||||
|
|
||||||
|
|
||||||
## 为什么选择lancet?
|
## 为什么选择lancet?
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ hero:
|
|||||||
features:
|
features:
|
||||||
- title: 全面
|
- title: 全面
|
||||||
icon: 💪
|
icon: 💪
|
||||||
details: 特性丰富,支持600+ go util函数。字符串、切片、日期时间、网络、加密、并发...
|
details: 功能全面,支持600+ go util函数。字符串、切片、日期时间、网络、加密、并发...
|
||||||
- title: 模块化设计
|
- title: 模块化设计
|
||||||
icon: 🏗
|
icon: 🏗
|
||||||
details: 每个模块设计成一个包,模块之间无耦合。
|
details: 每个模块设计成一个包,模块之间无耦合。
|
||||||
@@ -33,13 +33,21 @@ features:
|
|||||||
details: 结构良好,测试每个导出的函数。
|
details: 结构良好,测试每个导出的函数。
|
||||||
---
|
---
|
||||||
|
|
||||||
<p style="position:relative; top: -316px;left: 540px;">
|
<p style="position:relative;display: inline-block;top: -316px;left: 32%">
|
||||||
<img style="display: inline-block;margin-right:10px;" src="https://img.shields.io/github/stars/duke-git/lancet?style=social" alt="">
|
<img style="display: inline-block;margin-right:10px;" src="https://img.shields.io/github/stars/duke-git/lancet?style=social" alt="">
|
||||||
|
<img style="display: inline-block" src="https://img.shields.io/github/forks/duke-git/lancet?style=social" alt="">
|
||||||
<img style="display: inline-block" src="https://img.shields.io/github/forks/duke-git/lancet?style=social" alt="">
|
|
||||||
|
|
||||||
<!-- [](https://github.com/duke-git/lancet)
|
|
||||||
|
|
||||||
[](https://github.com/duke-git/lancet) -->
|
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<a style="border-color: #4565d8;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #4565d8;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 0 20px;
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
display: block;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 600;
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 140px;" href="/sponsor/sponsor.html">赞助</a>
|
||||||
|
|||||||
@@ -1,214 +0,0 @@
|
|||||||
# Structs
|
|
||||||
|
|
||||||
Struct is abstract struct for provide several high level functions
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## Source:
|
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/structs/struct.go](https://github.com/duke-git/lancet/blob/main/structs/struct.go)
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## Usage:
|
|
||||||
|
|
||||||
```go
|
|
||||||
import (
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## Index:
|
|
||||||
|
|
||||||
- [New](#New)
|
|
||||||
- [ToMap](#ToMap)
|
|
||||||
- [Fields](#Fields)
|
|
||||||
- [Field](#Field)
|
|
||||||
- [IsStruct](#IsStruct)
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## Documentation:
|
|
||||||
|
|
||||||
### <span id="New">New</span>
|
|
||||||
|
|
||||||
<p>The constructor function of the `Struct` </p>
|
|
||||||
|
|
||||||
<b>Signature:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func New(value any, tagName ...string) *Struct
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>Example:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
// to do something
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="ToMap">ToMap</span>
|
|
||||||
|
|
||||||
<p>convert a valid struct to a map</p>
|
|
||||||
|
|
||||||
<b>Signature:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) ToMap() (map[string]any, error)
|
|
||||||
```
|
|
||||||
|
|
||||||
> In addition, provided a convenient static function ToMap
|
|
||||||
|
|
||||||
```go
|
|
||||||
func ToMap(v any) (map[string]any, error)
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>Example:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
// use constructor function
|
|
||||||
s1 := structs.New(p1)
|
|
||||||
m1, _ := s1.ToMap()
|
|
||||||
|
|
||||||
fmt.Println(m1)
|
|
||||||
|
|
||||||
// use static function
|
|
||||||
m2, _ := structs.ToMap(p1)
|
|
||||||
|
|
||||||
fmt.Println(m2)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// map[name:11]
|
|
||||||
// map[name:11]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="Fields">Fields</span>
|
|
||||||
|
|
||||||
<p>Get all fields of a given struct, that the fields are abstract struct field</p>
|
|
||||||
|
|
||||||
<b>Signature:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) Fields() []*Field
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>Example:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
fields := s.Fields()
|
|
||||||
|
|
||||||
fmt.Println(len(fields))
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// 1
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="Field">Field</span>
|
|
||||||
|
|
||||||
<p>Get an abstract field of a struct by given field name </p>
|
|
||||||
|
|
||||||
<b>Signature:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) Field(name string) *Field
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>Example:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
f := s.Field("Name")
|
|
||||||
|
|
||||||
fmt.Println(f.Value())
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// 11
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="IsStruct">IsStruct</span>
|
|
||||||
|
|
||||||
<p>Check if the struct is valid</p>
|
|
||||||
|
|
||||||
<b>Signature:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) IsStruct() bool
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>Example:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
|
|
||||||
fmt.Println(s.IsStruct())
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,213 +0,0 @@
|
|||||||
# Structs
|
|
||||||
|
|
||||||
structs 包封装了一个抽象的`Struct`结构体,提供了操作`struct`的相关函数
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## 源码:
|
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/structs/struct.go](https://github.com/duke-git/lancet/blob/main/structs/struct.go)
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## 用法:
|
|
||||||
|
|
||||||
```go
|
|
||||||
import (
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## 目录:
|
|
||||||
|
|
||||||
- [New](#New)
|
|
||||||
- [ToMap](#ToMap)
|
|
||||||
- [Fields](#Fields)
|
|
||||||
- [Field](#Field)
|
|
||||||
- [IsStruct](#IsStruct)
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
|
||||||
|
|
||||||
## API 文档:
|
|
||||||
|
|
||||||
### <span id="New">New</span>
|
|
||||||
|
|
||||||
<p>`Struct`结构体的构造函数</p>
|
|
||||||
|
|
||||||
<b>函数签名:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func New(value any, tagName ...string) *Struct
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>示例:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
// to do something
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="ToMap">ToMap</span>
|
|
||||||
|
|
||||||
<p>将一个合法的struct对象转换为map[string]any</p>
|
|
||||||
|
|
||||||
<b>函数签名:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) ToMap() (map[string]any, error)
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>除此之外,提供一个便捷的静态方法 ToMap</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func ToMap(v any) (map[string]any, error)
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>示例:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s1 := structs.New(p1)
|
|
||||||
m1, _ := s1.ToMap()
|
|
||||||
|
|
||||||
fmt.Println(m1)
|
|
||||||
|
|
||||||
// 如果不需要Struct更多的方法,可以直接使用ToMap
|
|
||||||
m2, _ := structs.ToMap(p1)
|
|
||||||
|
|
||||||
fmt.Println(m2)
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// map[name:11]
|
|
||||||
// map[name:11]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="Fields">Fields</span>
|
|
||||||
|
|
||||||
<p>获取一个struct对象的属性列表</p>
|
|
||||||
|
|
||||||
<b>函数签名:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) Fields() []*Field
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>示例:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
fields := s.Fields()
|
|
||||||
|
|
||||||
fmt.Println(len(fields))
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// 1
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="Field">Field</span>
|
|
||||||
|
|
||||||
<p>根据属性名获取一个struct对象的属性</p>
|
|
||||||
|
|
||||||
<b>函数签名:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) Field(name string) *Field
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>示例:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
f := s.Field("Name")
|
|
||||||
|
|
||||||
fmt.Println(f.Value())
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// 11
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### <span id="IsStruct">IsStruct</span>
|
|
||||||
|
|
||||||
<p>判断是否为一个合法的struct对象</p>
|
|
||||||
|
|
||||||
<b>函数签名:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
func (s *Struct) IsStruct() bool
|
|
||||||
```
|
|
||||||
|
|
||||||
<b>示例:</b>
|
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/duke-git/lancet/v2/structs"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
type People struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
p1 := &People{Name: "11"}
|
|
||||||
s := structs.New(p1)
|
|
||||||
|
|
||||||
fmt.Println(s.IsStruct())
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
// true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"docs:dev": "vitepress dev",
|
"docs:dev": "vitepress dev",
|
||||||
"docs:build": "vitepress build",
|
"docs:build": "vitepress build --max_old_space_size=8192",
|
||||||
"docs:preview": "vitepress preview"
|
"docs:preview": "vitepress preview"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |
BIN
docs/public/sponsor_btn.png
Normal file
BIN
docs/public/sponsor_btn.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
docs/public/wechat_pay.png
Normal file
BIN
docs/public/wechat_pay.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
38
docs/sponsor/sponsor.md
Normal file
38
docs/sponsor/sponsor.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
### 赞助
|
||||||
|
|
||||||
|
<b>您好,我是一名软件开发者,从事开发工作 13 年。热爱软件开源。并愿意为此付出精力。是开源项目[lancet](https://github.com/duke-git/lancet)的作者。Lancet 自两年前开源发布以来,已有超过 1000 个内外部项目使用。lancet 一直会对所有用户免费。您的支持是对我继续奋斗的有力鼓励。谢谢! 微信扫描以下二维码或点击以下赞助按钮发起赞助。 </b>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.sponsor-ctn {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.sponsor-pay {
|
||||||
|
display: inline-block;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
.sponsor-btn {
|
||||||
|
border-color: #4565d8;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #4565d8;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 0 20px;
|
||||||
|
line-height: 40px;
|
||||||
|
font-size: 16px;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
text-align: center;
|
||||||
|
width: 140px;
|
||||||
|
position: absolute;
|
||||||
|
left: 360px;
|
||||||
|
top: 120px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class="sponsor-ctn">
|
||||||
|
<img src="../public/wechat_pay.png" width="260" height="260" class="sponsor-pay"/>
|
||||||
|
|
||||||
|
<a class="sponsor-btn" style="color: #fff;font-weight: 600;" href="https://liberapay.com/Duke_Du/donate" target="\_blank">赞助</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
*捐赠的资金将用于 lancet官网的维护和云服务器的费用支付。或者当我写代码困倦时,给我买杯 ☕️。*
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
.run-container {
|
|
||||||
float: right;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
@@ -18,10 +18,11 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/duke-git/lancet/v2/validator"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsExist checks if a file or directory exists.
|
// IsExist checks if a file or directory exists.
|
||||||
@@ -491,7 +492,7 @@ func CurrentPath() string {
|
|||||||
var absPath string
|
var absPath string
|
||||||
_, filename, _, ok := runtime.Caller(1)
|
_, filename, _, ok := runtime.Caller(1)
|
||||||
if ok {
|
if ok {
|
||||||
absPath = path.Dir(filename)
|
absPath = filepath.Dir(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
return absPath
|
return absPath
|
||||||
@@ -624,3 +625,24 @@ func WriteBytesToFile(filepath string, content []byte) error {
|
|||||||
_, err = f.Write(content)
|
_, err = f.Write(content)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadFile get file reader by a url or a local file
|
||||||
|
// Play: todo
|
||||||
|
func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error) {
|
||||||
|
switch {
|
||||||
|
case validator.IsUrl(path):
|
||||||
|
resp, err := http.Get(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, func() {}, err
|
||||||
|
}
|
||||||
|
return resp.Body, func() { resp.Body.Close() }, nil
|
||||||
|
case IsExist(path):
|
||||||
|
reader, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, func() {}, err
|
||||||
|
}
|
||||||
|
return reader, func() { reader.Close() }, nil
|
||||||
|
default:
|
||||||
|
return nil, func() {}, errors.New("unknown file type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package fileutil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -385,3 +386,20 @@ func ExampleWriteBytesToFile() {
|
|||||||
// Output:
|
// Output:
|
||||||
// hello
|
// hello
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleReadFile() {
|
||||||
|
reader, fn, err := ReadFile("https://httpbin.org/robots.txt")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer fn()
|
||||||
|
|
||||||
|
dat, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(string(dat))
|
||||||
|
// Output:
|
||||||
|
// User-agent: *
|
||||||
|
// Disallow: /deny
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package fileutil
|
package fileutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -457,3 +458,21 @@ func TestWriteBytesToFile(t *testing.T) {
|
|||||||
|
|
||||||
os.Remove(filepath)
|
os.Remove(filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadFile(t *testing.T) {
|
||||||
|
reader, close, err := ReadFile("https://httpbin.org/robots.txt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
defer close()
|
||||||
|
|
||||||
|
dat, err := io.ReadAll(reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
want := `User-agent: *
|
||||||
|
Disallow: /deny
|
||||||
|
`
|
||||||
|
internal.NewAssert(t, "TestReadFile").Equal(want, string(dat))
|
||||||
|
}
|
||||||
|
|||||||
1
fileutil/testdata/test1.csv
vendored
1
fileutil/testdata/test1.csv
vendored
@@ -1,2 +1,3 @@
|
|||||||
Lili,22,female
|
Lili,22,female
|
||||||
Jim,21,male
|
Jim,21,male
|
||||||
|
|
||||||
|
|||||||
|
1
fileutil/testdata/test2.csv
vendored
1
fileutil/testdata/test2.csv
vendored
@@ -1,2 +1,3 @@
|
|||||||
Lili,22,female
|
Lili,22,female
|
||||||
Jim,21,male
|
Jim,21,male
|
||||||
|
|
||||||
|
|||||||
|
@@ -29,14 +29,11 @@ func RandInt(min, max int) int {
|
|||||||
if min == max {
|
if min == max {
|
||||||
return min
|
return min
|
||||||
}
|
}
|
||||||
|
|
||||||
if max < min {
|
if max < min {
|
||||||
min, max = max, min
|
min, max = max, min
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix: https://github.com/duke-git/lancet/issues/75
|
|
||||||
// r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
||||||
// return r.Intn(max-min) + min
|
|
||||||
|
|
||||||
return rand.Intn(max-min) + min
|
return rand.Intn(max-min) + min
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1008,7 +1008,7 @@ func SortBy[T any](slice []T, less func(a, b T) bool) {
|
|||||||
// default sortType is ascending (asc), if descending order, set sortType to desc
|
// default sortType is ascending (asc), if descending order, set sortType to desc
|
||||||
// This function is deprecated, use Sort and SortBy for replacement.
|
// This function is deprecated, use Sort and SortBy for replacement.
|
||||||
// Play: https://go.dev/play/p/fU1prOBP9p1
|
// Play: https://go.dev/play/p/fU1prOBP9p1
|
||||||
func SortByField(slice any, field string, sortType ...string) error {
|
func SortByField[T any](slice []T, field string, sortType ...string) error {
|
||||||
sv := sliceValue(slice)
|
sv := sliceValue(slice)
|
||||||
t := sv.Type().Elem()
|
t := sv.Type().Elem()
|
||||||
|
|
||||||
@@ -1192,10 +1192,40 @@ func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T {
|
|||||||
|
|
||||||
// Join the slice item with specify separator.
|
// Join the slice item with specify separator.
|
||||||
// Play: https://go.dev/play/p/huKzqwNDD7V
|
// Play: https://go.dev/play/p/huKzqwNDD7V
|
||||||
func Join[T any](s []T, separator string) string {
|
func Join[T any](slice []T, separator string) string {
|
||||||
str := Map(s, func(_ int, item T) string {
|
str := Map(slice, func(_ int, item T) string {
|
||||||
return fmt.Sprint(item)
|
return fmt.Sprint(item)
|
||||||
})
|
})
|
||||||
|
|
||||||
return strings.Join(str, separator)
|
return strings.Join(str, separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Partition all slice elements with the evaluation of the given predicate functions.
|
||||||
|
// Play: https://go.dev/play/p/lkQ3Ri2NQhV
|
||||||
|
func Partition[T any](slice []T, predicates ...func(item T) bool) [][]T {
|
||||||
|
l := len(predicates)
|
||||||
|
|
||||||
|
result := make([][]T, l+1)
|
||||||
|
|
||||||
|
for _, item := range slice {
|
||||||
|
processed := false
|
||||||
|
|
||||||
|
for i, f := range predicates {
|
||||||
|
if f == nil {
|
||||||
|
panic("predicate function must not be nill")
|
||||||
|
}
|
||||||
|
|
||||||
|
if f(item) {
|
||||||
|
result[i] = append(result[i], item)
|
||||||
|
processed = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !processed {
|
||||||
|
result[l] = append(result[l], item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
@@ -1046,3 +1046,20 @@ func ExampleJoin() {
|
|||||||
// 1,2,3,4,5
|
// 1,2,3,4,5
|
||||||
// 1-2-3-4-5
|
// 1-2-3-4-5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExamplePartition() {
|
||||||
|
nums := []int{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
|
result1 := Partition(nums)
|
||||||
|
result2 := Partition(nums, func(n int) bool { return n%2 == 0 })
|
||||||
|
result3 := Partition(nums, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 })
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// [[1 2 3 4 5]]
|
||||||
|
// [[2 4] [1 3 5]]
|
||||||
|
// [[1 2] [3 4] [5]]
|
||||||
|
}
|
||||||
|
|||||||
@@ -1175,3 +1175,13 @@ func TestJoin(t *testing.T) {
|
|||||||
assert.Equal("1,2,3,4,5", result1)
|
assert.Equal("1,2,3,4,5", result1)
|
||||||
assert.Equal("1-2-3-4-5", result2)
|
assert.Equal("1-2-3-4-5", result2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPartition(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
assert := internal.NewAssert(t, "TestPartition")
|
||||||
|
|
||||||
|
assert.Equal([][]int{{1, 2, 3, 4, 5}}, Partition([]int{1, 2, 3, 4, 5}))
|
||||||
|
assert.Equal([][]int{{2, 4}, {1, 3, 5}}, Partition([]int{1, 2, 3, 4, 5}, func(n int) bool { return n%2 == 0 }))
|
||||||
|
assert.Equal([][]int{{1, 2}, {3, 4}, {5}}, Partition([]int{1, 2, 3, 4, 5}, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 }))
|
||||||
|
}
|
||||||
|
|||||||
@@ -408,6 +408,11 @@ func IsBlank(str string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNotBlank checks if a string is not whitespace, not empty.
|
||||||
|
func IsNotBlank(str string) bool {
|
||||||
|
return !IsBlank(str)
|
||||||
|
}
|
||||||
|
|
||||||
// HasPrefixAny check if a string starts with any of a slice of specified strings.
|
// HasPrefixAny check if a string starts with any of a slice of specified strings.
|
||||||
// Play: https://go.dev/play/p/8UUTl2C5slo
|
// Play: https://go.dev/play/p/8UUTl2C5slo
|
||||||
func HasPrefixAny(str string, prefixes []string) bool {
|
func HasPrefixAny(str string, prefixes []string) bool {
|
||||||
|
|||||||
@@ -479,6 +479,26 @@ func ExampleIsBlank() {
|
|||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleIsNotBlank() {
|
||||||
|
result1 := IsNotBlank("")
|
||||||
|
result2 := IsNotBlank(" ")
|
||||||
|
result3 := IsNotBlank("\t\v\f\n")
|
||||||
|
result4 := IsNotBlank(" 中文")
|
||||||
|
result5 := IsNotBlank(" world ")
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
fmt.Println(result3)
|
||||||
|
fmt.Println(result4)
|
||||||
|
fmt.Println(result5)
|
||||||
|
// Output:
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleHasPrefixAny() {
|
func ExampleHasPrefixAny() {
|
||||||
result1 := HasPrefixAny("foo bar", []string{"fo", "xyz", "hello"})
|
result1 := HasPrefixAny("foo bar", []string{"fo", "xyz", "hello"})
|
||||||
result2 := HasPrefixAny("foo bar", []string{"oom", "world"})
|
result2 := HasPrefixAny("foo bar", []string{"oom", "world"})
|
||||||
|
|||||||
@@ -427,6 +427,18 @@ func TestIsBlank(t *testing.T) {
|
|||||||
assert.Equal(IsBlank(" 中文"), false)
|
assert.Equal(IsBlank(" 中文"), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsNotBlank(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
assert := internal.NewAssert(t, "TestIsBlank")
|
||||||
|
assert.Equal(IsNotBlank(""), false)
|
||||||
|
assert.Equal(IsNotBlank(" "), false)
|
||||||
|
assert.Equal(IsNotBlank("\t\v\f\n"), false)
|
||||||
|
|
||||||
|
assert.Equal(IsNotBlank(" 中文"), true)
|
||||||
|
assert.Equal(IsNotBlank(" world "), true)
|
||||||
|
}
|
||||||
|
|
||||||
func TestHasPrefixAny(t *testing.T) {
|
func TestHasPrefixAny(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -16,19 +16,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
alphaMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]+$`)
|
alphaMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]+$`)
|
||||||
letterRegexMatcher *regexp.Regexp = regexp.MustCompile(`[a-zA-Z]`)
|
letterRegexMatcher *regexp.Regexp = regexp.MustCompile(`[a-zA-Z]`)
|
||||||
numberRegexMatcher *regexp.Regexp = regexp.MustCompile(`\d`)
|
numberRegexMatcher *regexp.Regexp = regexp.MustCompile(`\d`)
|
||||||
intStrMatcher *regexp.Regexp = regexp.MustCompile(`^[\+-]?\d+$`)
|
intStrMatcher *regexp.Regexp = regexp.MustCompile(`^[\+-]?\d+$`)
|
||||||
urlMatcher *regexp.Regexp = regexp.MustCompile(`^((ftp|http|https?):\/\/)?(\S+(:\S*)?@)?((([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(([a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*)|((www\.)?))?(([a-z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-z\x{00a1}-\x{ffff}]{2,}))?))(:(\d{1,5}))?((\/|\?|#)[^\s]*)?$`)
|
urlMatcher *regexp.Regexp = regexp.MustCompile(`^((ftp|http|https?):\/\/)?(\S+(:\S*)?@)?((([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(([a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*)|((www\.)?))?(([a-z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-z\x{00a1}-\x{ffff}]{2,}))?))(:(\d{1,5}))?((\/|\?|#)[^\s]*)?$`)
|
||||||
dnsMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$`)
|
dnsMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$`)
|
||||||
emailMatcher *regexp.Regexp = regexp.MustCompile(`\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`)
|
emailMatcher *regexp.Regexp = regexp.MustCompile(`\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`)
|
||||||
chineseMobileMatcher *regexp.Regexp = regexp.MustCompile(`^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$`)
|
chineseMobileMatcher *regexp.Regexp = regexp.MustCompile(`^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$`)
|
||||||
chineseIdMatcher *regexp.Regexp = regexp.MustCompile(`^[1-9]\d{5}(18|19|20|21|22)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$`)
|
chineseIdMatcher *regexp.Regexp = regexp.MustCompile(`^[1-9]\d{5}(18|19|20|21|22)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$`)
|
||||||
chineseMatcher *regexp.Regexp = regexp.MustCompile("[\u4e00-\u9fa5]")
|
chineseMatcher *regexp.Regexp = regexp.MustCompile("[\u4e00-\u9fa5]")
|
||||||
chinesePhoneMatcher *regexp.Regexp = regexp.MustCompile(`\d{3}-\d{8}|\d{4}-\d{7}|\d{4}-\d{8}`)
|
chinesePhoneMatcher *regexp.Regexp = regexp.MustCompile(`\d{3}-\d{8}|\d{4}-\d{7}|\d{4}-\d{8}`)
|
||||||
creditCardMatcher *regexp.Regexp = regexp.MustCompile(`^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11}|6[27][0-9]{14})$`)
|
creditCardMatcher *regexp.Regexp = regexp.MustCompile(`^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11}|6[27][0-9]{14})$`)
|
||||||
base64Matcher *regexp.Regexp = regexp.MustCompile(`^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$`)
|
base64Matcher *regexp.Regexp = regexp.MustCompile(`^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$`)
|
||||||
|
base64URLMatcher *regexp.Regexp = regexp.MustCompile(`^([A-Za-z0-9_-]{4})*([A-Za-z0-9_-]{2}(==)?|[A-Za-z0-9_-]{3}=?)?$`)
|
||||||
|
binMatcher *regexp.Regexp = regexp.MustCompile(`^(0b)?[01]+$`)
|
||||||
|
hexMatcher *regexp.Regexp = regexp.MustCompile(`^(#|0x|0X)?[0-9a-fA-F]+$`)
|
||||||
|
visaMatcher *regexp.Regexp = regexp.MustCompile(`^4[0-9]{12}(?:[0-9]{3})?$`)
|
||||||
|
masterCardMatcher *regexp.Regexp = regexp.MustCompile(`^5[1-5][0-9]{14}$`)
|
||||||
|
americanExpressMatcher *regexp.Regexp = regexp.MustCompile(`^3[47][0-9]{13}$`)
|
||||||
|
unionPay *regexp.Regexp = regexp.MustCompile("^62[0-5]\\d{13,16}$")
|
||||||
|
chinaUnionPay *regexp.Regexp = regexp.MustCompile(`^62[0-9]{14,17}$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsAlpha checks if the string contains only letters (a-zA-Z).
|
// IsAlpha checks if the string contains only letters (a-zA-Z).
|
||||||
@@ -401,3 +409,68 @@ func IsInt(v any) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsBin check if a give string is a valid binary value or not.
|
||||||
|
// Play: https://go.dev/play/p/ogPeg2XJH4P
|
||||||
|
func IsBin(v string) bool {
|
||||||
|
return binMatcher.MatchString(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsHex check if a give string is a valid hexadecimal value or not.
|
||||||
|
// Play: https://go.dev/play/p/M2qpHbEwmm7
|
||||||
|
func IsHex(v string) bool {
|
||||||
|
return hexMatcher.MatchString(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBase64URL check if a give string is a valid URL-safe Base64 encoded string.
|
||||||
|
// Play: https://go.dev/play/p/vhl4mr8GZ6S
|
||||||
|
func IsBase64URL(v string) bool {
|
||||||
|
return base64URLMatcher.MatchString(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsJWT check if a give string is a valid JSON Web Token (JWT).
|
||||||
|
// Play: https://go.dev/play/p/R6Op7heJbKI
|
||||||
|
func IsJWT(v string) bool {
|
||||||
|
strings := strings.Split(v, ".")
|
||||||
|
if len(strings) != 3 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range strings {
|
||||||
|
if !IsBase64URL(s) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsVisa check if a give string is a valid visa card nubmer or not.
|
||||||
|
// Play: https://go.dev/play/p/SdS2keOyJsl
|
||||||
|
func IsVisa(v string) bool {
|
||||||
|
return visaMatcher.MatchString(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsMasterCard check if a give string is a valid master card nubmer or not.
|
||||||
|
// Play: https://go.dev/play/p/CwWBFRrG27b
|
||||||
|
func IsMasterCard(v string) bool {
|
||||||
|
return masterCardMatcher.MatchString(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAmericanExpress check if a give string is a valid american expression card nubmer or not.
|
||||||
|
// Play: https://go.dev/play/p/HIDFpcOdpkd
|
||||||
|
func IsAmericanExpress(v string) bool {
|
||||||
|
return americanExpressMatcher.MatchString(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsUnionPay check if a give string is a valid union pay nubmer or not.
|
||||||
|
// Play: https://go.dev/play/p/CUHPEwEITDf
|
||||||
|
func IsUnionPay(v string) bool {
|
||||||
|
return unionPay.MatchString(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsChinaUnionPay check if a give string is a valid china union pay nubmer or not.
|
||||||
|
// Play: https://go.dev/play/p/yafpdxLiymu
|
||||||
|
func IsChinaUnionPay(v string) bool {
|
||||||
|
return chinaUnionPay.MatchString(v)
|
||||||
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user