https://github.com/edwin-luijten/go_command_bus
A simple command bus for go
https://github.com/edwin-luijten/go_command_bus
commandbus go hacktoberfest
Last synced: about 2 months ago
JSON representation
A simple command bus for go
- Host: GitHub
- URL: https://github.com/edwin-luijten/go_command_bus
- Owner: Edwin-Luijten
- License: mit
- Created: 2019-03-06T10:33:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-26T15:48:43.000Z (over 4 years ago)
- Last Synced: 2025-02-18T18:47:20.613Z (12 months ago)
- Topics: commandbus, go, hacktoberfest
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# A Command Bus for GO

[](https://pkg.go.dev/github.com/Edwin-Luijten/go_command_bus)
[](https://travis-ci.com/Edwin-Luijten/go_command_bus)
[](https://codeclimate.com/github/Edwin-Luijten/go_command_bus/maintainability)
[](https://codeclimate.com/github/Edwin-Luijten/go_command_bus/test_coverage)
## Installation
``` go get github.com/edwin-luijten/go_command_bus ```
## Usage
### Commands
```go
import (
commandbus "github.com/edwin-luijten/go_command_bus"
)
func main() {
bus := commandbus.New()
bus.RegisterHandler(&RegisterUserCommand{}, func(command interface{}) {
cmd := command.(*RegisterUserCommand)
fmt.Sprintf("Registered %s", cmd.Username)
})
bus.Handle(&RegisterUserCommand{
Email: "jj@email.com",
Password: "secret",
})
}
```
### Middleware's
A middleware has a handler and a priority.
Where priority of 0 is the least amount of priority.
```go
import (
commandbus "github.com/edwin-luijten/go_command_bus"
)
func main() {
bus := commandbus.New()
bus.RegisterMiddleware(func(command interface{}, next HandlerFunc) {
// your logic here
next(command)
// or here
}, 1)
}
```