mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
Compare commits
5 Commits
29a8318d6e
...
6dfdadd34e
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dfdadd34e | |||
| 8120c4db78 | |||
| 0d0f213d36 | |||
| 41d4bbf0e3 | |||
| fed1d5220e |
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
@@ -508,22 +508,22 @@ import "github.com/duke-git/lancet/v2/datetime"
|
|||||||
[[play](https://go.dev/play/p/nT1heB1KUUK)]
|
[[play](https://go.dev/play/p/nT1heB1KUUK)]
|
||||||
- **<big>AddWeek</big>** : add or sub week to time.
|
- **<big>AddWeek</big>** : add or sub week to time.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddWeek)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddWeek)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/M9TqdMiaA2p)]
|
||||||
- **<big>AddMonth</big>** : add or sub months to time.
|
- **<big>AddMonth</big>** : add or sub months to time.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddMonth)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddMonth)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/DLoiOnpLvsN)]
|
||||||
- **<big>AddYear</big>** : add or sub year to the time.
|
- **<big>AddYear</big>** : add or sub year to the time.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddYear)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddYear)]
|
||||||
[[play](https://go.dev/play/p/MqW2ujnBx10)]
|
[[play](https://go.dev/play/p/MqW2ujnBx10)]
|
||||||
- **<big>AddDaySafe</big>** : add or sub days to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
- **<big>AddDaySafe</big>** : add or sub days to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddDaySafe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddDaySafe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/JTohZFpoDJ3)]
|
||||||
- **<big>AddMonthSafe</big>** : add or sub months to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
- **<big>AddMonthSafe</big>** : add or sub months to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddMonthSafe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddMonthSafe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/KLw0lo6mbVW)]
|
||||||
- **<big>AddYearSafe</big>** : Add or sub years to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
- **<big>AddYearSafe</big>** : Add or sub years to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddYearSafe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#AddYearSafe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/KVGXWZZ54ZH)]
|
||||||
- **<big>BeginOfMinute</big>** : return the date time at the begin of minute of specific date.
|
- **<big>BeginOfMinute</big>** : return the date time at the begin of minute of specific date.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#BeginOfMinute)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/datetime.md#BeginOfMinute)]
|
||||||
[[play](https://go.dev/play/p/ieOLVJ9CiFT)]
|
[[play](https://go.dev/play/p/ieOLVJ9CiFT)]
|
||||||
@@ -705,34 +705,34 @@ import "github.com/duke-git/lancet/v2/eventbus"
|
|||||||
|
|
||||||
- **<big>NewEventBus</big>** : Create an EventBus instance.
|
- **<big>NewEventBus</big>** : Create an EventBus instance.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#NewEventBus)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#NewEventBus)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gHbOPV_NUOJ)]
|
||||||
- **<big>Subscribe</big>** : subscribes to an event with a specific event topic and listener function.
|
- **<big>Subscribe</big>** : subscribes to an event with a specific event topic and listener function.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#Subscribe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#Subscribe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/EYGf_8cHei-)]
|
||||||
- **<big>Unsubscribe</big>** : unsubscribes from an event with a specific event topic and listener function.
|
- **<big>Unsubscribe</big>** : unsubscribes from an event with a specific event topic and listener function.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#Unsubscribe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#Unsubscribe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/Tmh7Ttfvprf)]
|
||||||
- **<big>Publish</big>** : publishes an event with a specific event topic and data payload.
|
- **<big>Publish</big>** : publishes an event with a specific event topic and data payload.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#Publish)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#Publish)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gHTtVexFSH9)]
|
||||||
- **<big>ClearListeners</big>** : clears all the listeners.
|
- **<big>ClearListeners</big>** : clears all the listeners.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#ClearListeners)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#ClearListeners)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/KBfBYlKPgqD)]
|
||||||
- **<big>ClearListenersByTopic</big>** : clears all the listeners by topic.
|
- **<big>ClearListenersByTopic</big>** : clears all the listeners by topic.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#ClearListenersByTopic)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#ClearListenersByTopic)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gvMljmJOZmU)]
|
||||||
- **<big>GetListenersCount</big>** : returns the number of listeners for a specific event topic.
|
- **<big>GetListenersCount</big>** : returns the number of listeners for a specific event topic.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#GetListenersCount)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#GetListenersCount)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/8VPJsMQgStM)]
|
||||||
- **<big>GetAllListenersCount</big>** : returns the total number of all listeners.
|
- **<big>GetAllListenersCount</big>** : returns the total number of all listeners.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#GetAllListenersCount)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#GetAllListenersCount)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/PUlr0xcpEOz)]
|
||||||
- **<big>GetEvents</big>** : returns all the events topics.
|
- **<big>GetEvents</big>** : returns all the events topics.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#GetEvents)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#GetEvents)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/etgjjcOtAjX)]
|
||||||
- **<big>SetErrorHandler</big>** : sets the error handler function.
|
- **<big>SetErrorHandler</big>** : sets the error handler function.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#SetErrorHandler)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/eventbus.md#SetErrorHandler)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gmB0gnFe5mc)]
|
||||||
|
|
||||||
<h3 id="fileutil"> 9. Fileutil package implements some basic functions for file operations. <a href="#index">index</a></h3>
|
<h3 id="fileutil"> 9. Fileutil package implements some basic functions for file operations. <a href="#index">index</a></h3>
|
||||||
|
|
||||||
@@ -1479,7 +1479,7 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/b9iygtgsHI1)]
|
[[play](https://go.dev/play/p/b9iygtgsHI1)]
|
||||||
- **<big>EqualUnordered</big>** : Checks if two slices are equal: the same length and all elements value are equal (unordered).
|
- **<big>EqualUnordered</big>** : Checks if two slices are equal: the same length and all elements value are equal (unordered).
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#EqualUnordered)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#EqualUnordered)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/n8fSc2w8ZgX)]
|
||||||
- **<big>Every</big>** : return true if all of the values in the slice pass the predicate function.
|
- **<big>Every</big>** : return true if all of the values in the slice pass the predicate function.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Every)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Every)]
|
||||||
[[play](https://go.dev/play/p/R8U6Sl-j8cD)]
|
[[play](https://go.dev/play/p/R8U6Sl-j8cD)]
|
||||||
@@ -1581,7 +1581,7 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/YHvhnWGU3Ge)]
|
[[play](https://go.dev/play/p/YHvhnWGU3Ge)]
|
||||||
- **<big>ShuffleCopy</big>** : return a new slice with elements shuffled.
|
- **<big>ShuffleCopy</big>** : return a new slice with elements shuffled.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#ShuffleCopy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#ShuffleCopy)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/vqDa-Gs1vT0)]
|
||||||
- **<big>IsAscending</big>** : Checks if a slice is ascending order.
|
- **<big>IsAscending</big>** : Checks if a slice is ascending order.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#IsAscending)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#IsAscending)]
|
||||||
[[play](https://go.dev/play/p/9CtsFjet4SH)]
|
[[play](https://go.dev/play/p/9CtsFjet4SH)]
|
||||||
@@ -1730,7 +1730,7 @@ import "github.com/duke-git/lancet/v2/stream"
|
|||||||
[[play](https://go.dev/play/p/A8_zkJnLHm4)]
|
[[play](https://go.dev/play/p/A8_zkJnLHm4)]
|
||||||
- **<big>ReverseCopy</big>** : returns a new slice of element order is reversed to the given slice.
|
- **<big>ReverseCopy</big>** : returns a new slice of element order is reversed to the given slice.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#ReverseCopy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#ReverseCopy)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/c9arEaP7Cg-)]
|
||||||
- **<big>Range</big>** : returns a stream whose elements are in the range from start(included) to end(excluded) original stream.
|
- **<big>Range</big>** : returns a stream whose elements are in the range from start(included) to end(excluded) original stream.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#Range)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/stream.md#Range)]
|
||||||
[[play](https://go.dev/play/p/indZY5V2f4j)]
|
[[play](https://go.dev/play/p/indZY5V2f4j)]
|
||||||
@@ -1962,7 +1962,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
[[play](https://go.dev/play/p/Ay9UIk7Rum9)]
|
[[play](https://go.dev/play/p/Ay9UIk7Rum9)]
|
||||||
- **<big>FindAllOccurrences</big>** : Returns the positions of all occurrences of a substring in a string.
|
- **<big>FindAllOccurrences</big>** : Returns the positions of all occurrences of a substring in a string.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#FindAllOccurrences)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#FindAllOccurrences)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/uvyA6azGLB1)]
|
||||||
|
|
||||||
<h3 id="system"> 22. System package contain some functions about os, runtime, shell command. <a href="#index">index</a></h3>
|
<h3 id="system"> 22. System package contain some functions about os, runtime, shell command. <a href="#index">index</a></h3>
|
||||||
|
|
||||||
@@ -2218,7 +2218,7 @@ import "github.com/duke-git/lancet/v2/validator"
|
|||||||
[[play](https://go.dev/play/p/AHA0r0AzIdC)]
|
[[play](https://go.dev/play/p/AHA0r0AzIdC)]
|
||||||
- **<big>IsIpPort</big>** : check if the string is ip:port.
|
- **<big>IsIpPort</big>** : check if the string is ip:port.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsIpPort)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsIpPort)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/xUmls_b9L29)]
|
||||||
- **<big>IsStrongPassword</big>** : check if the string is strong password.
|
- **<big>IsStrongPassword</big>** : check if the string is strong password.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsStrongPassword)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsStrongPassword)]
|
||||||
[[play](https://go.dev/play/p/QHdVcSQ3uDg)]
|
[[play](https://go.dev/play/p/QHdVcSQ3uDg)]
|
||||||
|
|||||||
+21
-21
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
@@ -509,22 +509,22 @@ import "github.com/duke-git/lancet/v2/datetime"
|
|||||||
[[play](https://go.dev/play/p/nT1heB1KUUK)]
|
[[play](https://go.dev/play/p/nT1heB1KUUK)]
|
||||||
- **<big>AddWeek</big>** : 将日期加/减星期数.
|
- **<big>AddWeek</big>** : 将日期加/减星期数.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddWeek)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddWeek)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/M9TqdMiaA2p)]
|
||||||
- **<big>AddMonth</big>** : 将日期加/减月数.
|
- **<big>AddMonth</big>** : 将日期加/减月数.
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddMonth)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddMonth)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/DLoiOnpLvsN)]
|
||||||
- **<big>AddYear</big>** : 将日期加/减分年数。
|
- **<big>AddYear</big>** : 将日期加/减分年数。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddYear)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddYear)]
|
||||||
[[play](https://go.dev/play/p/MqW2ujnBx10)]
|
[[play](https://go.dev/play/p/MqW2ujnBx10)]
|
||||||
- **<big>AddDaySafe</big>** : 增加/减少指定的天数,并确保日期是有效日期。
|
- **<big>AddDaySafe</big>** : 增加/减少指定的天数,并确保日期是有效日期。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddDaySafe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddDaySafe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/JTohZFpoDJ3)]
|
||||||
- **<big>AddMonthSafe</big>** : 增加/减少指定的月份,并确保日期是有效日期。
|
- **<big>AddMonthSafe</big>** : 增加/减少指定的月份,并确保日期是有效日期。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddMonthSafe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddMonthSafe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/KLw0lo6mbVW)]
|
||||||
- **<big>AddYearSafe</big>** : 增加/减少指定的年份,并确保日期是有效日期。
|
- **<big>AddYearSafe</big>** : 增加/减少指定的年份,并确保日期是有效日期。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddYearSafe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#AddYearSafe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/KVGXWZZ54ZH)]
|
||||||
- **<big>BeginOfMinute</big>** : 返回指定时间的分钟开始时间。
|
- **<big>BeginOfMinute</big>** : 返回指定时间的分钟开始时间。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#BeginOfMinute)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/datetime.md#BeginOfMinute)]
|
||||||
[[play](https://go.dev/play/p/ieOLVJ9CiFT)]
|
[[play](https://go.dev/play/p/ieOLVJ9CiFT)]
|
||||||
@@ -704,34 +704,34 @@ import "github.com/duke-git/lancet/v2/eventbus"
|
|||||||
|
|
||||||
- **<big>NewEventBus</big>** : 创建EventBus实例。
|
- **<big>NewEventBus</big>** : 创建EventBus实例。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#NewEventBus)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#NewEventBus)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gHbOPV_NUOJ)]
|
||||||
- **<big>Subscribe</big>** : 订阅具有特定事件主题和监听函数的事件。支持异步,事件优先级,事件过滤器。
|
- **<big>Subscribe</big>** : 订阅具有特定事件主题和监听函数的事件。支持异步,事件优先级,事件过滤器。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#Subscribe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#Subscribe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/EYGf_8cHei-)]
|
||||||
- **<big>Unsubscribe</big>** : 取消订阅具有特定事件主题的事件。
|
- **<big>Unsubscribe</big>** : 取消订阅具有特定事件主题的事件。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#Unsubscribe)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#Unsubscribe)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/Tmh7Ttfvprf)]
|
||||||
- **<big>Publish</big>** : 发布一个带有特定事件主题和数据负载的事件。
|
- **<big>Publish</big>** : 发布一个带有特定事件主题和数据负载的事件。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#Publish)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#Publish)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gHTtVexFSH9)]
|
||||||
- **<big>ClearListeners</big>** : 清空所有事件监听器。
|
- **<big>ClearListeners</big>** : 清空所有事件监听器。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#ClearListeners)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#ClearListeners)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/KBfBYlKPgqD)]
|
||||||
- **<big>ClearListenersByTopic</big>** : 清空特定事件监听器。
|
- **<big>ClearListenersByTopic</big>** : 清空特定事件监听器。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#ClearListenersByTopic)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#ClearListenersByTopic)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gvMljmJOZmU)]
|
||||||
- **<big>GetListenersCount</big>** : 获取特定事件的监听器数量。
|
- **<big>GetListenersCount</big>** : 获取特定事件的监听器数量。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetListenersCount)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetListenersCount)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/8VPJsMQgStM)]
|
||||||
- **<big>GetAllListenersCount</big>** : 获取所有事件的监听器数量。
|
- **<big>GetAllListenersCount</big>** : 获取所有事件的监听器数量。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetAllListenersCount)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetAllListenersCount)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/PUlr0xcpEOz)]
|
||||||
- **<big>GetEvents</big>** : 获取所有事件的topic。
|
- **<big>GetEvents</big>** : 获取所有事件的topic。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetEvents)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#GetEvents)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/etgjjcOtAjX)]
|
||||||
- **<big>SetErrorHandler</big>** : 设置事件的错误处理函数。
|
- **<big>SetErrorHandler</big>** : 设置事件的错误处理函数。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#SetErrorHandler)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/eventbus.md#SetErrorHandler)]
|
||||||
[[play](https://go.dev/play/p/todo)]
|
[[play](https://go.dev/play/p/gmB0gnFe5mc)]
|
||||||
|
|
||||||
<h3 id="fileutil"> 10. fileutil 包含文件基本操作。 <a href="#index">回到目录</a></h3>
|
<h3 id="fileutil"> 10. fileutil 包含文件基本操作。 <a href="#index">回到目录</a></h3>
|
||||||
|
|
||||||
@@ -1477,7 +1477,7 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/b9iygtgsHI1)]
|
[[play](https://go.dev/play/p/b9iygtgsHI1)]
|
||||||
- **<big>EqualUnordered</big>** : 检查两个切片是否相等,元素数量相同,值相等,不考虑元素顺序。
|
- **<big>EqualUnordered</big>** : 检查两个切片是否相等,元素数量相同,值相等,不考虑元素顺序。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#EqualUnordered)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#EqualUnordered)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/n8fSc2w8ZgX)]
|
||||||
- **<big>Every</big>** : 如果切片中的所有值都通过谓词函数,则返回 true。
|
- **<big>Every</big>** : 如果切片中的所有值都通过谓词函数,则返回 true。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Every)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Every)]
|
||||||
[[play](https://go.dev/play/p/R8U6Sl-j8cD)]
|
[[play](https://go.dev/play/p/R8U6Sl-j8cD)]
|
||||||
@@ -1555,7 +1555,7 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/8uI8f1lwNrQ)]
|
[[play](https://go.dev/play/p/8uI8f1lwNrQ)]
|
||||||
- **<big>ReverseCopy</big>** : 反转切片中的元素顺序, 不改变原slice。
|
- **<big>ReverseCopy</big>** : 反转切片中的元素顺序, 不改变原slice。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#ReverseCopy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/stream.md#ReverseCopy)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/c9arEaP7Cg-)]
|
||||||
- **<big>Reduce<sup>deprecated</sup></big>** : 将切片中的元素依次运行 iteratee 函数,返回运行结果。(废弃:建议使用 ReduceBy)
|
- **<big>Reduce<sup>deprecated</sup></big>** : 将切片中的元素依次运行 iteratee 函数,返回运行结果。(废弃:建议使用 ReduceBy)
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Reduce)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Reduce)]
|
||||||
[[play](https://go.dev/play/p/_RfXJJWIsIm)]
|
[[play](https://go.dev/play/p/_RfXJJWIsIm)]
|
||||||
@@ -1582,7 +1582,7 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
[[play](https://go.dev/play/p/YHvhnWGU3Ge)]
|
[[play](https://go.dev/play/p/YHvhnWGU3Ge)]
|
||||||
- **<big>ShuffleCopy</big>** : 随机打乱切片中的元素顺序, 不改变原切片。
|
- **<big>ShuffleCopy</big>** : 随机打乱切片中的元素顺序, 不改变原切片。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#ShuffleCopy)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#ShuffleCopy)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/vqDa-Gs1vT0)]
|
||||||
- **<big>IsAscending</big>** : 检查切片元素是否按升序排列。
|
- **<big>IsAscending</big>** : 检查切片元素是否按升序排列。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#IsAscending)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#IsAscending)]
|
||||||
[[play](https://go.dev/play/p/9CtsFjet4SH)]
|
[[play](https://go.dev/play/p/9CtsFjet4SH)]
|
||||||
@@ -1962,7 +1962,7 @@ import "github.com/duke-git/lancet/v2/strutil"
|
|||||||
[[play](https://go.dev/play/p/Ay9UIk7Rum9)]
|
[[play](https://go.dev/play/p/Ay9UIk7Rum9)]
|
||||||
- **<big>FindAllOccurrences</big>** : 返回子字符串在字符串中所有出现的位置。
|
- **<big>FindAllOccurrences</big>** : 返回子字符串在字符串中所有出现的位置。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#FindAllOccurrences)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#FindAllOccurrences)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/uvyA6azGLB1)]
|
||||||
|
|
||||||
|
|
||||||
<h3 id="system"> 23. system 包含 os, runtime, shell command 的相关函数。 <a href="#index">回到目录</a></h3>
|
<h3 id="system"> 23. system 包含 os, runtime, shell command 的相关函数。 <a href="#index">回到目录</a></h3>
|
||||||
@@ -2220,7 +2220,7 @@ import "github.com/duke-git/lancet/v2/validator"
|
|||||||
[[play](https://go.dev/play/p/AHA0r0AzIdC)]
|
[[play](https://go.dev/play/p/AHA0r0AzIdC)]
|
||||||
- **<big>IsIpPort</big>** : 检查字符串是否是ip:port格式。
|
- **<big>IsIpPort</big>** : 检查字符串是否是ip:port格式。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpPort)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsIpPort)]
|
||||||
[[play](todo)]
|
[[play](https://go.dev/play/p/xUmls_b9L29)]
|
||||||
- **<big>IsStrongPassword</big>** : 验证字符串是否是强密码:(字母+数字+特殊字符)。
|
- **<big>IsStrongPassword</big>** : 验证字符串是否是强密码:(字母+数字+特殊字符)。
|
||||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsStrongPassword)]
|
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsStrongPassword)]
|
||||||
[[play](https://go.dev/play/p/QHdVcSQ3uDg)]
|
[[play](https://go.dev/play/p/QHdVcSQ3uDg)]
|
||||||
|
|||||||
@@ -1,51 +1,51 @@
|
|||||||
-----BEGIN rsa private key-----
|
-----BEGIN rsa private key-----
|
||||||
MIIJKAIBAAKCAgEAqX8BaBwlCUfe+J0D+bkRNky0/6aBVhxeeoIJY4FFdgewnloX
|
MIIJKAIBAAKCAgEA0HaqqGWnNqwRVKoJUUjYiH/dwkSK61La4RGYkvDfcuo9pDgc
|
||||||
Lc7vxRVgwpUvx1n/FkvulPFCOT65zDSV2kpgm3IZ8Y+gTlRg1S5Cu7QEsirlENhc
|
zHVhFUb/MYWeb3bAlFAGcZLYSBh6WAGxbeMjSkaLroaXnafhKZ2oXXUy8CzyYxZw
|
||||||
H4NMewpDWiTosS5G6+H8P5stf+do0u4TAoYifmE3JjEI2ewchfSGqy3YIzunVVOn
|
pLCDgJLG7Pf0jer3STZW93ZT8UJixbKwbqD6b8fkpMANwCYrTlXDWBuZVaEKuQNn
|
||||||
YSwAETOjXttLOYs7LLHQa2REo4fDaAVKebUv+aA4ldXvPlK16Nxf2JESNh4oeHxU
|
C4XufQis4fwRxRgfrZuLMvuQVtnyYmssmnp8JHovYkr87giDjEgvlrC84Lez32Zh
|
||||||
gBvcxkQDQDet7p7G30m/mNfVNeZJi5uOwnO1KIomAT8UosPoANpOXqtq1a4k7Udr
|
EhORRu5NGEDeZ1OewbkXGyQtbcBQYNAxgnOcO44MTTPhEdz4/A0xwzEe+yIOxWIA
|
||||||
IOJT6cXdFJ0byOdAfi5PlT0qOP4LtMs65SkmL3QoY9lvX2jBlfjNiOc5uJtcvvYa
|
WuEM2rclXpZBW/MEK41gZ3C04KcX5R0KRdj2PTTH7vJ33yRC4hKtWetwMvsUrewr
|
||||||
d2AMxqaeoig/xRYoUu0PNtbYjuzFkgYw7Tw3qcEOu9kZeTPUMQJoix54CgekBxeB
|
RKVcUgaeFykDAlgIDoSWvG0nzb70AWSoNcj7krLlwEc2WLGy/kCYWppnfYKafEJX
|
||||||
jxCKGJ0UPT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/8bPFQUlYFr7nefy2t1aL76diQnsBu4xHOtEMgSv
|
||||||
sIBzCz0CAStRBPNWZEePl1RDLoQkOEbnLHBJuEBEBSeOXgu3EIXB8vuv3uNYZGX2
|
F6d/pDFRC+PZN0B7glrz870jRaw9LNcuIBVoKN07hGBwD76EEZhCrn6eLqMI8srH
|
||||||
QAXjEhw+jMkluLrfIgtOCGIiY+ai9mLFdVgCDZZDrLUU9Ty0Re9UooxDhUdyteSB
|
YESDPUR/wl/PV8ZrA/hNRvjp44PYiLMYRDSQw8kpbLMMc0QgQCvhfMbYVvGteTmG
|
||||||
4l07NzrxRT64Gmsq2nNh2gsZ6EegZxW/ci7rrH0Fu6pE3x+QJ+jFdtMvjNo=
|
qdCFyy2x70wSh6Rfzb7WEWl15I4yfBTddXkJX82S+MrZu/Xq4FDtng594h0=
|
||||||
-----END rsa private key-----
|
-----END rsa private key-----
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
-----BEGIN rsa public key-----
|
-----BEGIN rsa public key-----
|
||||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqX8BaBwlCUfe+J0D+bkR
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0HaqqGWnNqwRVKoJUUjY
|
||||||
Nky0/6aBVhxeeoIJY4FFdgewnloXLc7vxRVgwpUvx1n/FkvulPFCOT65zDSV2kpg
|
iH/dwkSK61La4RGYkvDfcuo9pDgczHVhFUb/MYWeb3bAlFAGcZLYSBh6WAGxbeMj
|
||||||
m3IZ8Y+gTlRg1S5Cu7QEsirlENhcH4NMewpDWiTosS5G6+H8P5stf+do0u4TAoYi
|
SkaLroaXnafhKZ2oXXUy8CzyYxZwpLCDgJLG7Pf0jer3STZW93ZT8UJixbKwbqD6
|
||||||
fmE3JjEI2ewchfSGqy3YIzunVVOnYSwAETOjXttLOYs7LLHQa2REo4fDaAVKebUv
|
b8fkpMANwCYrTlXDWBuZVaEKuQNnC4XufQis4fw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Q==
|
||||||
-----END rsa public key-----
|
-----END rsa public key-----
|
||||||
|
|||||||
@@ -83,13 +83,13 @@ func AddDay(t time.Time, days int64) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddWeek add or sub weeks to the time.
|
// AddWeek add or sub weeks to the time.
|
||||||
// play: todo
|
// play: https://go.dev/play/p/M9TqdMiaA2p
|
||||||
func AddWeek(t time.Time, weeks int64) time.Time {
|
func AddWeek(t time.Time, weeks int64) time.Time {
|
||||||
return t.Add(7 * 24 * time.Hour * time.Duration(weeks))
|
return t.Add(7 * 24 * time.Hour * time.Duration(weeks))
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddMonth add or sub months to the time.
|
// AddMonth add or sub months to the time.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/DLoiOnpLvsN
|
||||||
func AddMonth(t time.Time, months int64) time.Time {
|
func AddMonth(t time.Time, months int64) time.Time {
|
||||||
return t.AddDate(0, int(months), 0)
|
return t.AddDate(0, int(months), 0)
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ func AddYear(t time.Time, year int64) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddDaySafe add or sub days to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
// AddDaySafe add or sub days to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/JTohZFpoDJ3
|
||||||
func AddDaySafe(t time.Time, days int) time.Time {
|
func AddDaySafe(t time.Time, days int) time.Time {
|
||||||
t = t.AddDate(0, 0, days)
|
t = t.AddDate(0, 0, days)
|
||||||
year, month, day := t.Date()
|
year, month, day := t.Date()
|
||||||
@@ -116,7 +116,7 @@ func AddDaySafe(t time.Time, days int) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddMonthSafe add or sub months to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
// AddMonthSafe add or sub months to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/KLw0lo6mbVW
|
||||||
func AddMonthSafe(t time.Time, months int) time.Time {
|
func AddMonthSafe(t time.Time, months int) time.Time {
|
||||||
year := t.Year()
|
year := t.Year()
|
||||||
month := int(t.Month()) + months
|
month := int(t.Month()) + months
|
||||||
@@ -141,7 +141,7 @@ func AddMonthSafe(t time.Time, months int) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddYearSafe add or sub years to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
// AddYearSafe add or sub years to the time and ensure that the returned date does not exceed the valid date of the target year and month.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/KVGXWZZ54ZH
|
||||||
func AddYearSafe(t time.Time, years int) time.Time {
|
func AddYearSafe(t time.Time, years int) time.Time {
|
||||||
year, month, day := t.Date()
|
year, month, day := t.Date()
|
||||||
year += years
|
year += years
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ func main() {
|
|||||||
func AddWeek(t time.Time, weeks int64) time.Time
|
func AddWeek(t time.Time, weeks int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/M9TqdMiaA2p)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -189,7 +189,7 @@ func main() {
|
|||||||
func AddMonth(t time.Time, months int64) time.Time
|
func AddMonth(t time.Time, months int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/DLoiOnpLvsN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -333,7 +333,7 @@ func main() {
|
|||||||
func AddDaySafe(t time.Time, days int) time.Time
|
func AddDaySafe(t time.Time, days int) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/JTohZFpoDJ3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -380,7 +380,7 @@ func main() {
|
|||||||
func AddMonthSafe(t time.Time, months int) time.Time
|
func AddMonthSafe(t time.Time, months int) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KLw0lo6mbVW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -417,7 +417,7 @@ func main() {
|
|||||||
func AddYearSafe(t time.Time, years int) time.Time
|
func AddYearSafe(t time.Time, years int) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KVGXWZZ54ZH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import (
|
|||||||
func NewEventBus[T any]() *EventBus[T]
|
func NewEventBus[T any]() *EventBus[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/gHbOPV_NUOJ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -65,7 +65,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) Subscribe(topic string, listener func(eventData T), async bool, priority int, filter func(eventData T) bool)
|
func (eb *EventBus[T]) Subscribe(topic string, listener func(eventData T), async bool, priority int, filter func(eventData T) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/EYGf_8cHei-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -106,8 +106,8 @@ func main() {
|
|||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, filter)
|
eb.Subscribe("event1", listener, false, 0, filter)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 2})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) Unsubscribe(topic string, listener func(eventData T))
|
func (eb *EventBus[T]) Unsubscribe(topic string, listener func(eventData T))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/Tmh7Ttfvprf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -145,7 +145,7 @@ func main() {
|
|||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
eb.Unsubscribe("event1", listener)
|
eb.Unsubscribe("event1", listener)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -161,10 +161,10 @@ func main() {
|
|||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (eb *EventBus[T]) Publish(event Event[T])
|
func (eb *EventBus[T]) Publish(event eventbus.Event[T])
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/gHTtVexFSH9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -179,7 +179,7 @@ func main() {
|
|||||||
fmt.Println(eventData)
|
fmt.Println(eventData)
|
||||||
}, false, 0, nil)
|
}, false, 0, nil)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 1
|
// 1
|
||||||
@@ -196,7 +196,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) ClearListeners()
|
func (eb *EventBus[T]) ClearListeners()
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/KBfBYlKPgqD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -213,9 +213,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
|
eb.Subscribe("event2", listener, false, 0, nil)
|
||||||
|
|
||||||
eb.ClearListeners()
|
eb.ClearListeners()
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
eb.Publish(eventbus.Event[int]{Topic: "event2", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -234,7 +237,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) ClearListenersByTopic(topic string)
|
func (eb *EventBus[T]) ClearListenersByTopic(topic string)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/gvMljmJOZmU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -251,14 +254,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
|
eb.Subscribe("event2", listener, false, 0, nil)
|
||||||
|
|
||||||
eb.ClearListenersByTopic("event1")
|
eb.ClearListenersByTopic("event1")
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
eb.Publish(eventbus.Event[int]{Topic: "event2", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 0
|
// 2
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -272,7 +278,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) GetListenersCount(topic string) int
|
func (eb *EventBus[T]) GetListenersCount(topic string) 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/j6yaJ2xAmFz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -284,14 +290,14 @@ func main() {
|
|||||||
eb := eventbus.NewEventBus[int]()
|
eb := eventbus.NewEventBus[int]()
|
||||||
|
|
||||||
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
||||||
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
eb.Subscribe("event2", func(eventData int) {}, false, 0, nil)
|
||||||
|
|
||||||
count := eb.GetListenersCount("event1")
|
count := eb.GetListenersCount("event1")
|
||||||
|
|
||||||
fmt.Println(count)
|
fmt.Println(count)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 2
|
// 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -305,7 +311,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) GetAllListenersCount() int
|
func (eb *EventBus[T]) GetAllListenersCount() 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/PUlr0xcpEOz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -338,7 +344,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) GetEvents() []string
|
func (eb *EventBus[T]) GetEvents() []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/etgjjcOtAjX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -359,8 +365,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// event1
|
|
||||||
// event2
|
// event2
|
||||||
|
// event1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -374,7 +380,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) SetErrorHandler(handler func(err error))
|
func (eb *EventBus[T]) SetErrorHandler(handler func(err 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/gmB0gnFe5mc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -393,7 +399,7 @@ func main() {
|
|||||||
panic("error")
|
panic("error")
|
||||||
}, false, 0, nil)
|
}, false, 0, nil)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// error
|
// error
|
||||||
|
|||||||
@@ -887,7 +887,7 @@ func main() {
|
|||||||
func EqualUnordered[T comparable](slice1, slice2 []T) bool
|
func EqualUnordered[T comparable](slice1, slice2 []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/n8fSc2w8ZgX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1772,7 +1772,7 @@ func main() {
|
|||||||
func ReverseCopy[T any](slice []T) []T
|
func ReverseCopy[T any](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/c9arEaP7Cg-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2065,7 +2065,7 @@ func main() {
|
|||||||
func ShuffleCopy[T any](slice []T) []T
|
func ShuffleCopy[T any](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/vqDa-Gs1vT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1772,7 +1772,7 @@ func main() {
|
|||||||
func FindAllOccurrences(str, substr string) []int
|
func FindAllOccurrences(str, substr string) []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/uvyA6azGLB1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1001,7 +1001,7 @@ func main() {
|
|||||||
func IsIpPort(str string) bool
|
func IsIpPort(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block">[运行](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/xUmls_b9L29)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ func main() {
|
|||||||
func AddWeek(t time.Time, weeks int64) time.Time
|
func AddWeek(t time.Time, weeks int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/M9TqdMiaA2p)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -191,7 +191,7 @@ func main() {
|
|||||||
func AddMonth(t time.Time, months int64) time.Time
|
func AddMonth(t time.Time, months int64) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/DLoiOnpLvsN)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -335,7 +335,7 @@ func main() {
|
|||||||
func AddDaySafe(t time.Time, days int) time.Time
|
func AddDaySafe(t time.Time, days int) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/JTohZFpoDJ3)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -382,7 +382,7 @@ func main() {
|
|||||||
func AddMonthSafe(t time.Time, months int) time.Time
|
func AddMonthSafe(t time.Time, months int) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KLw0lo6mbVW)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -419,7 +419,7 @@ func main() {
|
|||||||
func AddYearSafe(t time.Time, years int) time.Time
|
func AddYearSafe(t time.Time, years int) time.Time
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KVGXWZZ54ZH)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import (
|
|||||||
func NewEventBus[T any]() *EventBus[T]
|
func NewEventBus[T any]() *EventBus[T]
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/gHbOPV_NUOJ)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -65,7 +65,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) Subscribe(topic string, listener func(eventData T), async bool, priority int, filter func(eventData T) bool)
|
func (eb *EventBus[T]) Subscribe(topic string, listener func(eventData T), async bool, priority int, filter func(eventData T) bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/EYGf_8cHei-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -106,8 +106,8 @@ func main() {
|
|||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, filter)
|
eb.Subscribe("event1", listener, false, 0, filter)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 2})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) Unsubscribe(topic string, listener func(eventData T))
|
func (eb *EventBus[T]) Unsubscribe(topic string, listener func(eventData T))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/Tmh7Ttfvprf)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -145,7 +145,7 @@ func main() {
|
|||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
eb.Unsubscribe("event1", listener)
|
eb.Unsubscribe("event1", listener)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -161,10 +161,10 @@ func main() {
|
|||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (eb *EventBus[T]) Publish(event Event[T])
|
func (eb *EventBus[T]) Publish(event eventbus.Event[T])
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/gHTtVexFSH9)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -179,7 +179,7 @@ func main() {
|
|||||||
fmt.Println(eventData)
|
fmt.Println(eventData)
|
||||||
}, false, 0, nil)
|
}, false, 0, nil)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 1
|
// 1
|
||||||
@@ -196,7 +196,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) ClearListeners()
|
func (eb *EventBus[T]) ClearListeners()
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/KBfBYlKPgqD)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -213,9 +213,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
|
eb.Subscribe("event2", listener, false, 0, nil)
|
||||||
|
|
||||||
eb.ClearListeners()
|
eb.ClearListeners()
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
eb.Publish(eventbus.Event[int]{Topic: "event2", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -234,7 +237,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) ClearListenersByTopic(topic string)
|
func (eb *EventBus[T]) ClearListenersByTopic(topic string)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/gvMljmJOZmU)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -251,14 +254,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
|
eb.Subscribe("event2", listener, false, 0, nil)
|
||||||
|
|
||||||
eb.ClearListenersByTopic("event1")
|
eb.ClearListenersByTopic("event1")
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
eb.Publish(eventbus.Event[int]{Topic: "event2", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 0
|
// 2
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -272,7 +278,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) GetListenersCount(topic string) int
|
func (eb *EventBus[T]) GetListenersCount(topic string) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/j6yaJ2xAmFz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -284,14 +290,14 @@ func main() {
|
|||||||
eb := eventbus.NewEventBus[int]()
|
eb := eventbus.NewEventBus[int]()
|
||||||
|
|
||||||
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
||||||
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
eb.Subscribe("event2", func(eventData int) {}, false, 0, nil)
|
||||||
|
|
||||||
count := eb.GetListenersCount("event1")
|
count := eb.GetListenersCount("event1")
|
||||||
|
|
||||||
fmt.Println(count)
|
fmt.Println(count)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 2
|
// 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -305,7 +311,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) GetAllListenersCount() int
|
func (eb *EventBus[T]) GetAllListenersCount() int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/PUlr0xcpEOz)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -338,7 +344,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) GetEvents() []string
|
func (eb *EventBus[T]) GetEvents() []string
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/etgjjcOtAjX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -359,8 +365,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// event1
|
|
||||||
// event2
|
// event2
|
||||||
|
// event1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -374,7 +380,7 @@ func main() {
|
|||||||
func (eb *EventBus[T]) SetErrorHandler(handler func(err error))
|
func (eb *EventBus[T]) SetErrorHandler(handler func(err error))
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/gmB0gnFe5mc)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -393,7 +399,7 @@ func main() {
|
|||||||
panic("error")
|
panic("error")
|
||||||
}, false, 0, nil)
|
}, false, 0, nil)
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(eventbus.Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// error
|
// error
|
||||||
|
|||||||
@@ -852,7 +852,7 @@ func main() {
|
|||||||
func EqualUnordered[T comparable](slice1, slice2 []T) bool
|
func EqualUnordered[T comparable](slice1, slice2 []T) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/n8fSc2w8ZgX)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -1768,7 +1768,7 @@ func main() {
|
|||||||
func ReverseCopy[T any](slice []T) []T
|
func ReverseCopy[T any](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/c9arEaP7Cg-)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -2062,7 +2062,7 @@ func main() {
|
|||||||
func ShuffleCopy[T any](slice []T) []T
|
func ShuffleCopy[T any](slice []T) []T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/vqDa-Gs1vT0)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1774,7 +1774,7 @@ func main() {
|
|||||||
func FindAllOccurrences(str, substr string) []int
|
func FindAllOccurrences(str, substr string) []int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/uvyA6azGLB1)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1003,7 +1003,7 @@ func main() {
|
|||||||
func IsIpPort(str string) bool
|
func IsIpPort(str string) bool
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>Example:<span style="float:right;display:inline-block">[Run](todo)</span></b>
|
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/xUmls_b9L29)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
|
|||||||
+10
-9
@@ -33,7 +33,7 @@ type EventListener[T any] struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewEventBus creates a new EventBus.
|
// NewEventBus creates a new EventBus.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/gHbOPV_NUOJ
|
||||||
func NewEventBus[T any]() *EventBus[T] {
|
func NewEventBus[T any]() *EventBus[T] {
|
||||||
return &EventBus[T]{
|
return &EventBus[T]{
|
||||||
listeners: sync.Map{},
|
listeners: sync.Map{},
|
||||||
@@ -41,7 +41,7 @@ func NewEventBus[T any]() *EventBus[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe subscribes to an event with a specific event topic and listener function.
|
// Subscribe subscribes to an event with a specific event topic and listener function.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/EYGf_8cHei-
|
||||||
func (eb *EventBus[T]) Subscribe(topic string, listener func(eventData T), async bool, priority int, filter func(eventData T) bool) {
|
func (eb *EventBus[T]) Subscribe(topic string, listener func(eventData T), async bool, priority int, filter func(eventData T) bool) {
|
||||||
eb.mu.Lock()
|
eb.mu.Lock()
|
||||||
defer eb.mu.Unlock()
|
defer eb.mu.Unlock()
|
||||||
@@ -65,7 +65,7 @@ func (eb *EventBus[T]) Subscribe(topic string, listener func(eventData T), async
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unsubscribe unsubscribes from an event with a specific event topic and listener function.
|
// Unsubscribe unsubscribes from an event with a specific event topic and listener function.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/Tmh7Ttfvprf
|
||||||
func (eb *EventBus[T]) Unsubscribe(topic string, listener func(eventData T)) {
|
func (eb *EventBus[T]) Unsubscribe(topic string, listener func(eventData T)) {
|
||||||
eb.mu.Lock()
|
eb.mu.Lock()
|
||||||
defer eb.mu.Unlock()
|
defer eb.mu.Unlock()
|
||||||
@@ -89,7 +89,7 @@ func (eb *EventBus[T]) Unsubscribe(topic string, listener func(eventData T)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Publish publishes an event with a specific event topic and data payload.
|
// Publish publishes an event with a specific event topic and data payload.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/gHTtVexFSH9
|
||||||
func (eb *EventBus[T]) Publish(event Event[T]) {
|
func (eb *EventBus[T]) Publish(event Event[T]) {
|
||||||
eb.mu.RLock()
|
eb.mu.RLock()
|
||||||
defer eb.mu.RUnlock()
|
defer eb.mu.RUnlock()
|
||||||
@@ -125,12 +125,13 @@ func (eb *EventBus[T]) publishToListener(listener *EventListener[T], event Event
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetErrorHandler sets the error handler function.
|
// SetErrorHandler sets the error handler function.
|
||||||
|
// Play: https://go.dev/play/p/gmB0gnFe5mc
|
||||||
func (eb *EventBus[T]) SetErrorHandler(handler func(err error)) {
|
func (eb *EventBus[T]) SetErrorHandler(handler func(err error)) {
|
||||||
eb.errorHandler = handler
|
eb.errorHandler = handler
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearListeners clears all the listeners.
|
// ClearListeners clears all the listeners.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/KBfBYlKPgqD
|
||||||
func (eb *EventBus[T]) ClearListeners() {
|
func (eb *EventBus[T]) ClearListeners() {
|
||||||
eb.mu.Lock()
|
eb.mu.Lock()
|
||||||
defer eb.mu.Unlock()
|
defer eb.mu.Unlock()
|
||||||
@@ -139,7 +140,7 @@ func (eb *EventBus[T]) ClearListeners() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ClearListenersByTopic clears all the listeners by topic.
|
// ClearListenersByTopic clears all the listeners by topic.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/gvMljmJOZmU
|
||||||
func (eb *EventBus[T]) ClearListenersByTopic(topic string) {
|
func (eb *EventBus[T]) ClearListenersByTopic(topic string) {
|
||||||
eb.mu.Lock()
|
eb.mu.Lock()
|
||||||
defer eb.mu.Unlock()
|
defer eb.mu.Unlock()
|
||||||
@@ -148,7 +149,7 @@ func (eb *EventBus[T]) ClearListenersByTopic(topic string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetListenersCount returns the number of listeners for a specific event topic.
|
// GetListenersCount returns the number of listeners for a specific event topic.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/8VPJsMQgStM
|
||||||
func (eb *EventBus[T]) GetListenersCount(topic string) int {
|
func (eb *EventBus[T]) GetListenersCount(topic string) int {
|
||||||
eb.mu.RLock()
|
eb.mu.RLock()
|
||||||
defer eb.mu.RUnlock()
|
defer eb.mu.RUnlock()
|
||||||
@@ -163,7 +164,7 @@ func (eb *EventBus[T]) GetListenersCount(topic string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllListenersCount returns the total number of listeners.
|
// GetAllListenersCount returns the total number of listeners.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/PUlr0xcpEOz
|
||||||
func (eb *EventBus[T]) GetAllListenersCount() int {
|
func (eb *EventBus[T]) GetAllListenersCount() int {
|
||||||
eb.mu.RLock()
|
eb.mu.RLock()
|
||||||
defer eb.mu.RUnlock()
|
defer eb.mu.RUnlock()
|
||||||
@@ -178,7 +179,7 @@ func (eb *EventBus[T]) GetAllListenersCount() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEvents returns all the events topics.
|
// GetEvents returns all the events topics.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/etgjjcOtAjX
|
||||||
func (eb *EventBus[T]) GetEvents() []string {
|
func (eb *EventBus[T]) GetEvents() []string {
|
||||||
eb.mu.RLock()
|
eb.mu.RLock()
|
||||||
defer eb.mu.RUnlock()
|
defer eb.mu.RUnlock()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func ExampleEventBus_Unsubscribe() {
|
|||||||
// 0
|
// 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleEventBus_Subscribe_WithFilter() {
|
func ExampleEventBus_Subscribe_withFilter() {
|
||||||
eb := NewEventBus[int]()
|
eb := NewEventBus[int]()
|
||||||
|
|
||||||
receivedData := 0
|
receivedData := 0
|
||||||
@@ -60,7 +60,7 @@ func ExampleEventBus_Subscribe_WithFilter() {
|
|||||||
// 1
|
// 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleEventBus_Subscribe_WithPriority() {
|
func ExampleEventBus_Subscribe_withPriority() {
|
||||||
eb := NewEventBus[int]()
|
eb := NewEventBus[int]()
|
||||||
|
|
||||||
eb.Subscribe("event1", func(eventData int) {
|
eb.Subscribe("event1", func(eventData int) {
|
||||||
@@ -78,7 +78,7 @@ func ExampleEventBus_Subscribe_WithPriority() {
|
|||||||
// 1
|
// 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleEventBus_Subscribe_Async() {
|
func ExampleEventBus_Subscribe_async() {
|
||||||
eb := NewEventBus[int]()
|
eb := NewEventBus[int]()
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
@@ -136,9 +136,12 @@ func ExampleEventBus_ClearListeners() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
|
eb.Subscribe("event2", listener, false, 0, nil)
|
||||||
|
|
||||||
eb.ClearListeners()
|
eb.ClearListeners()
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
eb.Publish(Event[int]{Topic: "event2", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
@@ -155,28 +158,31 @@ func ExampleEventBus_ClearListenersByTopic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eb.Subscribe("event1", listener, false, 0, nil)
|
eb.Subscribe("event1", listener, false, 0, nil)
|
||||||
|
eb.Subscribe("event2", listener, false, 0, nil)
|
||||||
|
|
||||||
eb.ClearListenersByTopic("event1")
|
eb.ClearListenersByTopic("event1")
|
||||||
|
|
||||||
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
eb.Publish(Event[int]{Topic: "event1", Payload: 1})
|
||||||
|
eb.Publish(Event[int]{Topic: "event2", Payload: 2})
|
||||||
|
|
||||||
fmt.Println(receivedData)
|
fmt.Println(receivedData)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 0
|
// 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleEventBus_GetListenersCount() {
|
func ExampleEventBus_GetListenersCount() {
|
||||||
eb := NewEventBus[int]()
|
eb := NewEventBus[int]()
|
||||||
|
|
||||||
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
||||||
eb.Subscribe("event1", func(eventData int) {}, false, 0, nil)
|
eb.Subscribe("event2", func(eventData int) {}, false, 0, nil)
|
||||||
|
|
||||||
count := eb.GetListenersCount("event1")
|
count := eb.GetListenersCount("event1")
|
||||||
|
|
||||||
fmt.Println(count)
|
fmt.Println(count)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 2
|
// 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleEventBus_SetErrorHandler() {
|
func ExampleEventBus_SetErrorHandler() {
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ func TestEventBus_Unsubscribe(t *testing.T) {
|
|||||||
assert.Equal(0, receivedData)
|
assert.Equal(0, receivedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventBus_Subscribe_WithFilter(t *testing.T) {
|
func TestEventBus_Subscribe_withFilter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
assert := internal.NewAssert(t, "TestEventBus_Subscribe_WithFilter")
|
assert := internal.NewAssert(t, "TestEventBus_Subscribe_withFilter")
|
||||||
|
|
||||||
eb := NewEventBus[int]()
|
eb := NewEventBus[int]()
|
||||||
|
|
||||||
@@ -64,9 +64,9 @@ func TestEventBus_Subscribe_WithFilter(t *testing.T) {
|
|||||||
assert.Equal(1, receivedData)
|
assert.Equal(1, receivedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventBus_Subscribe_WithPriority(t *testing.T) {
|
func TestEventBus_Subscribe_withPriority(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
assert := internal.NewAssert(t, "TestEventBus_Subscribe_WithPriority")
|
assert := internal.NewAssert(t, "TestEventBus_Subscribe_withPriority")
|
||||||
|
|
||||||
eb := NewEventBus[int]()
|
eb := NewEventBus[int]()
|
||||||
|
|
||||||
@@ -87,9 +87,9 @@ func TestEventBus_Subscribe_WithPriority(t *testing.T) {
|
|||||||
assert.Equal([]int{2, 1}, receivedData)
|
assert.Equal([]int{2, 1}, receivedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventBus_Subscribe_Async(t *testing.T) {
|
func TestEventBus_Subscribe_async(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
assert := internal.NewAssert(t, "TestEventBus_Subscribe_Async")
|
assert := internal.NewAssert(t, "TestEventBus_Subscribe_async")
|
||||||
|
|
||||||
eb := NewEventBus[string]()
|
eb := NewEventBus[string]()
|
||||||
|
|
||||||
@@ -215,6 +215,5 @@ func TestEventBus_GetEvents(t *testing.T) {
|
|||||||
events := eb.GetEvents()
|
events := eb.GetEvents()
|
||||||
|
|
||||||
assert.Equal(2, len(events))
|
assert.Equal(2, len(events))
|
||||||
assert.Equal("event1", events[0])
|
assert.EqualValues([]string{"event1", "event2"}, events)
|
||||||
assert.Equal("event2", events[1])
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -221,7 +221,7 @@ func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EqualUnordered checks if two slices are equal: the same length and all elements' value are equal (unordered).
|
// EqualUnordered checks if two slices are equal: the same length and all elements' value are equal (unordered).
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/n8fSc2w8ZgX
|
||||||
func EqualUnordered[T comparable](slice1, slice2 []T) bool {
|
func EqualUnordered[T comparable](slice1, slice2 []T) bool {
|
||||||
if len(slice1) != len(slice2) {
|
if len(slice1) != len(slice2) {
|
||||||
return false
|
return false
|
||||||
@@ -1003,7 +1003,7 @@ func Reverse[T any](slice []T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReverseCopy return a new slice of element order is reversed to the given slice.
|
// ReverseCopy return a new slice of element order is reversed to the given slice.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/c9arEaP7Cg-
|
||||||
func ReverseCopy[T any](slice []T) []T {
|
func ReverseCopy[T any](slice []T) []T {
|
||||||
result := make([]T, len(slice))
|
result := make([]T, len(slice))
|
||||||
|
|
||||||
@@ -1027,7 +1027,7 @@ func Shuffle[T any](slice []T) []T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ShuffleCopy return a new slice with elements shuffled.
|
// ShuffleCopy return a new slice with elements shuffled.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/vqDa-Gs1vT0
|
||||||
func ShuffleCopy[T any](slice []T) []T {
|
func ShuffleCopy[T any](slice []T) []T {
|
||||||
result := make([]T, len(slice))
|
result := make([]T, len(slice))
|
||||||
copy(result, slice)
|
copy(result, slice)
|
||||||
|
|||||||
+1
-1
@@ -758,7 +758,7 @@ func ExtractContent(str, start, end string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindAllOccurrences returns the positions of all occurrences of a substring in a string.
|
// FindAllOccurrences returns the positions of all occurrences of a substring in a string.
|
||||||
// Play: todo
|
// Play: https://go.dev/play/p/uvyA6azGLB1
|
||||||
func FindAllOccurrences(str, substr string) []int {
|
func FindAllOccurrences(str, substr string) []int {
|
||||||
var positions []int
|
var positions []int
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ func IsIp(ipstr string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsIpPort check if the string is ip:port.
|
// IsIpPort check if the string is ip:port.
|
||||||
// Play:
|
// Play: https://go.dev/play/p/xUmls_b9L29
|
||||||
func IsIpPort(str string) bool {
|
func IsIpPort(str string) bool {
|
||||||
host, port, err := net.SplitHostPort(str)
|
host, port, err := net.SplitHostPort(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user