Skip to content
Simple command bus for GO
Go Makefile
Branch: master
Clone or download
Pull request Compare This branch is 2 commits behind vsmoraes:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
middleware
.gitignore
.travis.yml
LICENSE
Makefile
README.md
commandbus.go
commandbus_test.go
go.mod
go.sum

README.md

GO CommandBus

Build Status Codecov branch GoDoc Go Report Card License

A slight and pluggable command-bus for Go.

Install

Use go get.

$ go get github.com/vsmoraes/go-commandbus

Then import the package into your own code:

import "github.com/vsmoraes/go-commandbus"

Usage

package main

import (
	"context"
	"log"

	"github.com/vsmoraes/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.Fatal(err)
	}

	err = bus.Execute(context.Background(), &CreateUser{"go-commandbus"})

	if err != nil {
		log.Fatal(err)
	}
}

License

This project is released under the MIT licence. See LICENSE for more details.

You can’t perform that action at this time.