A slight and pluggable command-bus for Go.
Use go get.
$ go get github.com/lana/go-commandbus
Then import the package into your own code:
import "github.com/lana/go-commandbus"
package main
import (
"context"
"log"
"github.com/lana/go-commandbus"
)
type CreateUser struct {
Name string
}
func CreateHandler(ctx context.Context, cmd *CreateUser) error {
log.Printf("user %s created", cmd.Name)
return nil
}
func main() {
bus := commandbus.New()
err := bus.Register(&CreateUser{}, CreateHandler)
if err != nil {
log.Error(err)
os.Exit(1)
}
err = bus.Execute(context.Background(), &CreateUser{"go-commandbus"})
if err != nil {
log.Error(err)
os.Exit(1)
}
}
This project is released under the MIT licence. See LICENSE for more details.