sequbus
is a generic and lightweight sequential command bus for Go. It allows you to register and execute a series of commands in a strict order. Inspired by middleware and pipeline patterns.
- ✅ Generic: works with any data type
- ✅ Sequential: commands run one after another
- ✅ Chainable: register multiple commands easily
- ✅ Early exit on error
- ✅ Simple interface
go get github.com/go-nop/sequbus
type User struct {
ID string
Name string
}
type ValidateUser struct{}
func (v ValidateUser) Run(ctx context.Context, user *User) error {
if user.ID == "" {
return errors.New("missing ID")
}
return nil
}
bus := sequbus.New[*User]()
bus.Register(ValidateUser{})
// bus.Register(SendWelcomeEmail{}) // More commands
user := &User{ID: "123", Name: "Alice"}
err := bus.Dispatch(context.Background(), user)
if err != nil {
log.Fatal(err)
}
Run all tests:
go test ./...
sequbus/
├── bus.go // CommandBus implementation
├── bus_test.go // Unit tests
├── node.go // Command node implementation
├── node_test.go // Unit tests
├── runner/
└── interface.go // runner.Interface definition
└── example/
└── main.go // Example usage
type Interface[T any] interface {
Run(ctx context.Context, data T) error
}
Implement this interface to create custom commands.
- User registration pipeline
- Data processing workflows
- Approval chains
- Middleware-like systems in CLI or microservices
MIT
Made with ❤️ by @go-nop