Skip to content

Edwin-Luijten/go_command_bus

Folders and files

NameName
Last commit message
Last commit date
Mar 8, 2019
Mar 8, 2019
Oct 26, 2021
Oct 26, 2021
Oct 26, 2021
Mar 11, 2019
Mar 14, 2019
Oct 26, 2021
Oct 26, 2021
Mar 11, 2019
Mar 11, 2019

Repository files navigation

A Command Bus for GO

GitHub go.mod Go version Go Reference Build Status Maintainability Test Coverage

Installation

go get github.com/edwin-luijten/go_command_bus

Usage

Commands

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.

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) 
}

About

A simple command bus for go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages