Skip to content
/ sequbus Public

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.

License

Notifications You must be signed in to change notification settings

go-nop/sequbus

Repository files navigation

sequbus

License Release GolangVersion Go Reference

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.

✨ Features

  • ✅ Generic: works with any data type
  • ✅ Sequential: commands run one after another
  • ✅ Chainable: register multiple commands easily
  • ✅ Early exit on error
  • ✅ Simple interface

📦 Installation

go get github.com/go-nop/sequbus

🚀 Usage

1. Define Your Data and Command(s)

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
}

2. Register Commands to the Bus

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

🧪 Testing

Run all tests:

go test ./...

📂 Project Structure

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

📘 Interface

type Interface[T any] interface {
	Run(ctx context.Context, data T) error
}

Implement this interface to create custom commands.


🛠 Example Use Cases

  • User registration pipeline
  • Data processing workflows
  • Approval chains
  • Middleware-like systems in CLI or microservices

📄 License

MIT


Made with ❤️ by @go-nop

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published