Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chenmingyong0423/go-eventbus
Implement eventbus in go.
https://github.com/chenmingyong0423/go-eventbus
Last synced: about 2 months ago
JSON representation
Implement eventbus in go.
- Host: GitHub
- URL: https://github.com/chenmingyong0423/go-eventbus
- Owner: chenmingyong0423
- License: apache-2.0
- Created: 2024-05-12T19:19:06.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-13T14:33:50.000Z (8 months ago)
- Last Synced: 2024-11-01T23:30:32.267Z (2 months ago)
- Language: Go
- Size: 19.5 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EventBus
Implement eventbus in go.
# Install
```go
go get github.com/chenmingyong0423/go-eventbus
```# Usage
```go
type PostInfo struct {
PostId string `json:"post_id"`
Title string `json:"title"`
Author string `json:"author"`
}eventBus := eventbus.NewEventBus()
subscribe := eventBus.Subscribe("post")
go func() {
postInfo := PostInfo{
PostId: "1",
Title: "Implement eventbus in Go",
Author: "陈明勇",
}
bytes, err := json.Marshal(postInfo)
if err != nil {
panic(err)
}
eventBus.Publish("post", eventbus.Event{Payload: bytes})
}()event := <-subscribe
var postInfo PostInfo
err := json.Unmarshal(event.Payload, &postInfo)
if err != nil {
panic(err)
}
fmt.Println(postInfo)
```