Skip to content

A Go library for building complex, type-safe workflows from simple steps.

License

Notifications You must be signed in to change notification settings

sam-fredrickson/flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flow

A Go library for building complex, type-safe workflows from simple steps.

Installation

go get github.com/sam-fredrickson/flow

Quick Example

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

Key Features

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:

Documentation

  • 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/flow or visit pkg.go.dev

About

A Go library for building complex, type-safe workflows from simple steps.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •