Skip to content

Commit

Permalink
doc: add play ground demo
Browse files Browse the repository at this point in the history
  • Loading branch information
duke-git committed Oct 9, 2024
1 parent 5d6ab72 commit 213e2b4
Show file tree
Hide file tree
Showing 30 changed files with 293 additions and 275 deletions.
104 changes: 54 additions & 50 deletions README.md

Large diffs are not rendered by default.

103 changes: 53 additions & 50 deletions README_zh-CN.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cryptor/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func AesOfbDecrypt(data, key []byte) []byte {
}

// AesGcmEncrypt encrypt data with key use AES GCM algorithm
// Play: todo
// Play: https://go.dev/play/p/rUt0-DmsPCs
func AesGcmEncrypt(data, key []byte) []byte {
block, err := aes.NewCipher(key)
if err != nil {
Expand All @@ -268,7 +268,7 @@ func AesGcmEncrypt(data, key []byte) []byte {
}

// AesGcmDecrypt decrypt data with key use AES GCM algorithm
// Play: todo
// Play: https://go.dev/play/p/rUt0-DmsPCs
func AesGcmDecrypt(data, key []byte) []byte {
block, err := aes.NewCipher(key)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions datetime/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func TimestampNano(timezone ...string) int64 {

// TrackFuncTime track the time of function execution.
// call it at top of the func like `defer TrackFuncTime(time.Now())()`
// Play: todo
// Play: https://go.dev/play/p/QBSEdfXHPTp
func TrackFuncTime(pre time.Time) func() {
callerName := getCallerName()
return func() {
Expand Down Expand Up @@ -413,7 +413,7 @@ func getCallerName() string {
}

// DaysBetween returns the number of days between two times.
// Play: todo
// Play: https://go.dev/play/p/qD6qGb3TbOy
func DaysBetween(start, end time.Time) int {
duration := end.Sub(start)
days := int(duration.Hours() / 24)
Expand All @@ -424,7 +424,7 @@ func DaysBetween(start, end time.Time) int {
// GenerateDatetimesBetween returns a slice of strings between two times.
// layout: the format of the datetime string
// interval: the interval between two datetimes
// Play: todo
// Play: https://go.dev/play/p/6kHBpAxD9ZC
func GenerateDatetimesBetween(start, end time.Time, layout string, interval string) ([]string, error) {
var result []string

Expand Down
4 changes: 2 additions & 2 deletions docs/api/packages/cryptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func main() {
func AesGcmEncrypt(data, key []byte) []byte
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/rUt0-DmsPCs)</span></b>

```go
package main
Expand Down Expand Up @@ -425,7 +425,7 @@ func main() {
func AesGcmDecrypt(data, key []byte) []byte
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/rUt0-DmsPCs)</span></b>

```go
package main
Expand Down
6 changes: 3 additions & 3 deletions docs/api/packages/datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ func main() {
func TrackFuncTime(pre time.Time) func()
```

<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/QBSEdfXHPTp)</span></b>

```go
package main
Expand Down Expand Up @@ -1511,7 +1511,7 @@ func main() {
func DaysBetween(start, end time.Time) int
```

<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/qD6qGb3TbOy)</span></b>

```go
package main
Expand Down Expand Up @@ -1544,7 +1544,7 @@ func main() {
func GenerateDatetimesBetween(start, end time.Time, layout string, interval string) ([]string, error)
```

<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/6kHBpAxD9ZC)</span></b>

```go
package main
Expand Down
4 changes: 2 additions & 2 deletions docs/api/packages/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func main() {
func Debounce(fn func(), delay time.Duration) (debouncedFn func(), cancelFn func())
```

<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/-dGFrYn_1Zi)</span></b>

```go
package main
Expand Down Expand Up @@ -753,7 +753,7 @@ func main() {
func Throttle(fn func(), interval time.Duration) func()
```

<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HpoMov-tJSN)</span></b>

```go
package main
Expand Down
53 changes: 28 additions & 25 deletions docs/api/packages/maputil.md
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ func main() {
func (om *OrderedMap[K, V]) Set(key K, value V)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Y4ZJ_oOc1FU)</span></b>

```go
package main
Expand Down Expand Up @@ -1230,7 +1230,7 @@ func main() {
func (om *OrderedMap[K, V]) Get(key K) (V, bool)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Y4ZJ_oOc1FU)</span></b>

```go
package main
Expand Down Expand Up @@ -1270,7 +1270,7 @@ func main() {
func (om *OrderedMap[K, V]) Delete(key K)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/5bIi4yaZ3K-)</span></b>

```go
package main
Expand Down Expand Up @@ -1306,7 +1306,7 @@ func main() {
func (om *OrderedMap[K, V]) Clear()
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8LwoJyEfuFr)</span></b>

```go
package main
Expand Down Expand Up @@ -1345,7 +1345,7 @@ func (om *OrderedMap[K, V]) Front() (struct {
}, bool)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/ty57XSimpoe)</span></b>

```go
package main
Expand Down Expand Up @@ -1385,7 +1385,7 @@ func (om *OrderedMap[K, V]) Back() (struct {
}, bool)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/rQMjp1yQmpa)</span></b>

```go
package main
Expand All @@ -1402,12 +1402,12 @@ func main() {
om.Set("b", 2)
om.Set("c", 3)

frontElement, ok := om.Front()
fmt.Println(frontElement)
backElement, ok := om.Back()
fmt.Println(backElement)
fmt.Println(ok)

// Output:
// {a 1}
// {c 3}
// true
}
```
Expand All @@ -1422,7 +1422,7 @@ func main() {
func (om *OrderedMap[K, V]) Range(iteratee func(key K, value V) bool)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/U-KpORhc7LZ)</span></b>

```go
package main
Expand Down Expand Up @@ -1461,7 +1461,7 @@ func main() {
func (om *OrderedMap[K, V]) Keys() []K
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Vv_y9ExKclA)</span></b>

```go
package main
Expand Down Expand Up @@ -1497,7 +1497,7 @@ func main() {
func (om *OrderedMap[K, V]) Values() []V
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/TWj5n1-PUfx)</span></b>

```go
package main
Expand Down Expand Up @@ -1533,7 +1533,7 @@ func main() {
func (om *OrderedMap[K, V]) Elements() []struct
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/4BHG4kKz6bB)</span></b>

```go
package main
Expand Down Expand Up @@ -1569,7 +1569,7 @@ func main() {
func (om *OrderedMap[K, V]) Len() int
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/cLe6z2VX5N-)</span></b>

```go
package main
Expand Down Expand Up @@ -1605,7 +1605,7 @@ func main() {
func (om *OrderedMap[K, V]) Contains(key K) bool
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/QuwqqnzwDNX)</span></b>

```go
package main
Expand Down Expand Up @@ -1647,7 +1647,7 @@ func (om *OrderedMap[K, V]) Iter() <-chan struct {
}
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/tlq2tdvicPt)</span></b>

```go
package main
Expand Down Expand Up @@ -1688,7 +1688,7 @@ func (om *OrderedMap[K, V]) ReverseIter() <-chan struct {
}
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8Q0ssg6hZzO)</span></b>

```go
package main
Expand Down Expand Up @@ -1726,7 +1726,7 @@ func main() {
func (om *OrderedMap[K, V]) SortByKey(less func(a, b K) bool)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/N7hjD_alZPq)</span></b>

```go
package main
Expand All @@ -1737,7 +1737,7 @@ import (
)

func main() {
om := maputil.NewOrderedMap[string, int]()
om := maputil.NewOrderedMap[int, string]()

om.Set(3, "c")
om.Set(1, "a")
Expand Down Expand Up @@ -1765,7 +1765,7 @@ func main() {
func (om *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/C-wAwydIAC7)</span></b>

```go
package main
Expand All @@ -1776,7 +1776,7 @@ import (
)

func main() {
om := maputil.NewOrderedMap[string, int]()
om := maputil.NewOrderedMap[int, string]()

om.Set(3, "c")
om.Set(1, "a")
Expand All @@ -1802,7 +1802,7 @@ func main() {
func (om *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
```

<b>示例:<span style="float:right;display:inline-block;">[运行]()</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/8C3MvJ3-mut)</span></b>

```go
package main
Expand All @@ -1822,6 +1822,7 @@ func main() {
fmt.Println(om.Elements())

// Output:
// [{a 1} {b 2} {c 3}]
}
```

Expand Down Expand Up @@ -2239,7 +2240,7 @@ func main() {
func SortByKey[K constraints.Ordered, V any](m map[K]V) (sortedKeysMap map[K]V)
```

<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/PVdmBSnm6P_W)</span></b>

```go
package main
Expand All @@ -2257,7 +2258,9 @@ func main() {
2: "b",
}

result := maputil.SortByKey(m)
result := maputil.SortByKey(m, func(a, b int) bool {
return a < b
})

fmt.Println(result)

Expand All @@ -2276,7 +2279,7 @@ func main() {
func GetOrDefault[K comparable, V any](m map[K]V, key K, defaultValue V) V
```

<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/99QjSYSBdiM)</span></b>

```go
package main
Expand Down
Loading

0 comments on commit 213e2b4

Please sign in to comment.