Skip to content

Commit

Permalink
style: update readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 14, 2022
1 parent 3e31336 commit 87452f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Lightweight event management, dispatch tool library implemented by Go

- `On/Listen(name string, listener Listener, priority ...int)` Register event listener
- `Subscribe/AddSubscriber(sbr Subscriber)` Subscribe to support registration of multiple event listeners
- `Trigger/Fire(name string, params M) (error, Event)` Trigger event
- `Trigger/Fire(name string, params M) (error, Event)` Trigger event by name and params
- `MustTrigger/MustFire(name string, params M) Event` Trigger event, there will be panic if there is an error
- `FireEvent(e Event) (err error)` Trigger an event based on a given event instance
- `FireBatch(es ...interface{}) (ers []error)` Trigger multiple events at once
Expand Down Expand Up @@ -106,6 +106,8 @@ will trigger the execution of the `dbListener1` listener.

### Using anonymous functions

You can use anonymous function for quick write an event lister.

```go
package mypgk

Expand All @@ -128,6 +130,8 @@ func Run() {

### Using the structure method

You can use struct write an event lister, and it should implementation interface `event.Listener`.

**interface:**

```go
Expand Down Expand Up @@ -158,6 +162,9 @@ func (l *MyListener) Handle(e event.Event) error {

## Register multiple event listeners

Can implementation interface `event.Subscriber` for register
multiple event listeners at once.

**interface:**

```go
Expand Down Expand Up @@ -209,6 +216,9 @@ func (s *MySubscriber) e1Handler(e event.Event) error {

## Write custom events

If you want to customize the event object or define some fixed event information in advance,
you can implement the `event.Event` interface.

**interface:**

```go
Expand Down Expand Up @@ -262,8 +272,6 @@ event.Fire("e1", nil)
// event.FireEvent(e)
```



## Gookit packages

- [gookit/ini](https://github.com/gookit/ini) Go config management, use INI files
Expand Down
2 changes: 2 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ func (s *MySubscriber) e1Handler(e event.Event) error {

## 编写自定义事件

如果你希望自定义事件对象或者提前定义好一些固定事件信息,可以实现 `event.Event` 接口.

**interface:**

```go
Expand Down

0 comments on commit 87452f4

Please sign in to comment.