Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.67 KB

README.md

File metadata and controls

56 lines (42 loc) · 1.67 KB

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: "jj@email.com",
    	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) 
}