-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
293 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,59 @@ | ||
package events | ||
|
||
// 默认事件 | ||
// default new events | ||
var defaultEvent = New() | ||
|
||
// 默认事件 | ||
// default new events | ||
func Default() *Events { | ||
return defaultEvent | ||
} | ||
|
||
// 注册操作 | ||
// Add Action | ||
func AddAction(event any, listener any, sort int) { | ||
Default.Action().Listen(event, listener, sort) | ||
defaultEvent.Action().Listen(event, listener, sort) | ||
} | ||
|
||
// 触发操作 | ||
// Do Action | ||
func DoAction(event any, params ...any) { | ||
Default.Action().Trigger(event, params...) | ||
defaultEvent.Action().Trigger(event, params...) | ||
} | ||
|
||
// 移除操作 | ||
// Remove Action | ||
func RemoveAction(event string, listener any, sort int) bool { | ||
return Default.Action().RemoveListener(event, listener, sort) | ||
return defaultEvent.Action().RemoveListener(event, listener, sort) | ||
} | ||
|
||
// 是否有操作 | ||
// Has Action | ||
func HasAction(event string, listener any) bool { | ||
return Default.Action().HasListener(event, listener) | ||
return defaultEvent.Action().HasListener(event, listener) | ||
} | ||
|
||
// 注册过滤器 | ||
// Add Filter | ||
func AddFilter(event any, listener any, sort int) { | ||
Default.Filter().Listen(event, listener, sort) | ||
defaultEvent.Filter().Listen(event, listener, sort) | ||
} | ||
|
||
// 触发过滤器 | ||
// Apply Filters | ||
func ApplyFilters(event any, params ...any) any { | ||
return Default.Filter().Trigger(event, params...) | ||
return defaultEvent.Filter().Trigger(event, params...) | ||
} | ||
|
||
// 移除过滤器 | ||
// Remove Filter | ||
func RemoveFilter(event string, listener any, sort int) bool { | ||
return Default.Filter().RemoveListener(event, listener, sort) | ||
return defaultEvent.Filter().RemoveListener(event, listener, sort) | ||
} | ||
|
||
// 是否有过滤器 | ||
// Has Filter | ||
func HasFilter(event string, listener any) bool { | ||
return Default.Filter().HasListener(event, listener) | ||
return defaultEvent.Filter().HasListener(event, listener) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package goch | ||
|
||
import ( | ||
"testing" | ||
"reflect" | ||
) | ||
|
||
func AssertEqualT(t *testing.T) func(any, any, string) { | ||
return func(actual any, expected any, msg string) { | ||
if !reflect.DeepEqual(actual, expected) { | ||
t.Errorf("Failed %s: actual: %v, expected: %v", msg, actual, expected) | ||
} | ||
} | ||
} | ||
|
||
func Test_ToJSON(t *testing.T) { | ||
eq := AssertEqualT(t) | ||
|
||
test := map[string]any{ | ||
"test1": "value1", | ||
"test5": "value5", | ||
} | ||
|
||
res := ToJSON(test) | ||
check := `{"test1":"value1","test5":"value5"}` | ||
|
||
eq(string(res), check, "Test_ToJSON") | ||
} | ||
|
||
func Test_ToString(t *testing.T) { | ||
eq := AssertEqualT(t) | ||
|
||
test := []byte("test1") | ||
|
||
res := ToString(test) | ||
check := `test1` | ||
|
||
eq(string(res), check, "Test_ToString") | ||
} |
Oops, something went wrong.