Skip to content

Type-Safe Event Processingfor Go

Build composable event pipelines with conditional execution and middleware support. Event-driven architecture that the compiler can verify. Choose the naming convention that fits your team: SQL, BDD, Kafka Streams, or MapReduce.

type SQLRule[I, O any] struct {
    ID     string         // Unique ID
    Select Action[I, O]   // Transform
    Into   Destination[O] // Output
    From   Source[I]      // Event source
    Where  Condition[I]   // Input condition
    Having Condition[O]  // Output condition
}

One pipeline, four naming conventions: SQL, BDD (Given-When-Then), Kafka Streams, or MapReduce.

⚠️

The Problem

Event handling scattered across codebases. Difficult to test, hard to modify, impossible to compose. Side effects mixed with business logic. No reusability.

✨

The Solution

Declarative event pipelines with type safety. Composable components. Middleware for cross-cutting concerns.

Features

🔒

Type-Safe Pipelines

Generic types ensure compile-time correctness from source to destination. The compiler verifies your event flows.

🎯

Zero Dependencies

Any Go type works as an event. No interface requirements. Works seamlessly with existing types.

📋

Declarative Conditions

Boolean expressions for event filtering. Rich operators for numbers, strings, and collections.

🔌

Unified Middleware

Single interface for callbacks, transformations, and destinations. Composable cross-cutting concerns.

⚡

Source Fanout

Shared sources start once and distribute events to all registered rules automatically.

Quick Start

Install via Go modules
go get github.com/emad-elsaid/firehose

Hello World: Timer Events

package main

import (
    "context"
    "fmt"
    "time"
    
    fh "github.com/emad-elsaid/firehose"
    "github.com/emad-elsaid/firehose/condition"
)

type Tick struct {
    Time time.Time
}

func (t Tick) Get(key string) (any, error) {
    if key == "hour" {
        return t.Time.Hour(), nil
    }
    return nil, fmt.Errorf("unknown: %s", key)
}

func main() {
    ctx := context.Background()
    
    rule := &fh.SQLRule[Tick, string]{
        ID:     "business_hours",
        Select: FormatTime{},
        Into:   Printer{},
        From:   Timer{Interval: 1 * time.Second},
        Where:  condition.Cond[Tick]("hour >= 9 and hour < 17"),
    }
    
    head, _ := fh.Add(ctx, nil, rule)
    doneChannels := fh.Start(ctx, head, nil)
    for _, ch := range doneChannels {
        <-ch
    }
}

Core Concepts

01

Event Source

Produces events of a specific type. HTTP servers, message queues, timers, file watchers.

type Source[T any] interface
02

Condition

Optional filter evaluated against event attributes. Boolean expressions or custom logic.

type Condition[I any] interface
03

Transformation

Converts input events to output events. Business logic, enrichment, validation.

type Action[I, O any] interface
04

Destination

Handles output events. Database writes, API calls, message publishing, logging.

type Destination[T any] interface

Event Processing Pipeline

📡
Source
Emit Event
→
🔍
Condition
Filter Input
→
⚙️
Action
Transform
→
🔍
Condition
Filter Output
→
📤
Sink
Consume

Use Cases

🌐 Microservices

HTTP routing, gRPC streams, WebSocket distribution

📊 Stream Processing

Kafka consumers, real-time chat, log aggregation

🔍 System Monitoring

Process tracking, file watching, metric collection

🤖 Automation

Workflow orchestration, rule engines, ETL pipelines

🎮 Interactive Systems

Game input, UI events, hardware integration

📡 Event-Driven Apps

CQRS, event sourcing, saga patterns

Ready to Build Type-Safe Pipelines?

Start building composable, testable event processing systems in Go

Released under the MIT License.