Categorygithub.com/lana/go-commandbus
modulepackage
0.1.0
Repository: https://github.com/lana/go-commandbus.git
Documentation: pkg.go.dev

# README

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/lana/go-commandbus

Then import the package into your own code:

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

Usage

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.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.

# Packages

No description provided by the author

# Functions

No description provided by the author

# Interfaces

CommandBus is the definition of how command should be handled.

# Type aliases

HandlerFunc defines a function to execute the command handler.
MiddlewareFunc defines a function to process middleware.