Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-26T15:48:43.000Z (about 3 years ago)
- Last Synced: 2024-07-27T23:23:44.229Z (5 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
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/edwin-luijten/go_command_bus?style=flat-square)
[![Go Reference](https://pkg.go.dev/badge/github.com/Edwin-Luijten/go_command_bus.svg)](https://pkg.go.dev/github.com/Edwin-Luijten/go_command_bus)
[![Build Status](https://travis-ci.com/Edwin-Luijten/go_command_bus.svg?branch=master)](https://travis-ci.com/Edwin-Luijten/go_command_bus)
[![Maintainability](https://api.codeclimate.com/v1/badges/ff5d37cbc59ef9a174a5/maintainability)](https://codeclimate.com/github/Edwin-Luijten/go_command_bus/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/ff5d37cbc59ef9a174a5/test_coverage)](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: "[email protected]",
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)
}
```