A Go library for building complex, type-safe workflows from simple steps.
go get github.com/sam-fredrickson/flowimport "github.com/sam-fredrickson/flow"
type Config struct {
DatabaseURL string
}
// Define steps that operate on *Config
setupDb := func(ctx context.Context, cfg *Config) error {
return setupDatabase(ctx, cfg.DatabaseURL)
}
runMigrations := func(ctx context.Context, cfg *Config) error {
return applyMigrations(ctx, cfg.DatabaseURL)
}
// Compose workflow
workflow := flow.Do(setupDb, runMigrations)
// Execute it
cfg := &Config{DatabaseURL: "postgres://..."}
if err := workflow(context.Background(), cfg); err != nil {
log.Fatal(err)
}Automatic retry with exponential backoff and jitter:
flow.Retry(
CallExternalAPI(),
flow.UpTo(3),
flow.ExponentialBackoff(100*time.Millisecond, flow.WithFullJitter()),
)
// Those are the default settings, so this can be simplified
flow.Retry(CallExternalAPI())Parallel execution with automatic error handling and goroutine management:
flow.InParallel(flow.Steps(
DeployService("web"),
DeployService("api"),
DeployService("worker"),
))Dynamic workflows where steps are determined at runtime:
flow.InParallel(
flow.ForEach(GetServices, DeployService),
)For more sophisticated patterns, see:
- Configuration-driven orchestration — Components declare their needs, orchestration layer optimizes execution
- Data transformation pipelines — Type-safe functional composition for processing collections
- Feature Guide — Complete guide covering all features and patterns
- Design Philosophy — Understanding the principles and motivation behind the library
- Complete Examples — Runnable examples showing real-world usage
- Package documentation: Run
go doc github.com/sam-fredrickson/flowor visit pkg.go.dev