A Go library for concurrent applications with rate limiting, task scheduling, and streaming.
Rate Limiting (pkg/ratelimit)
- Token bucket and leaky bucket algorithms
- Concurrency limiting
- Prometheus metrics
Task Scheduling (pkg/scheduling)
- Worker pools with graceful shutdown
- Cron-based scheduling
- Multi-stage pipelines
- Context-aware timeouts
Streaming (pkg/streaming)
- Functional stream operations
- Background buffering
- Backpressure control
- Channel utilities
go get github.com/vnykmshr/goflowpackage main
import (
"context"
"fmt"
"log"
"time"
"github.com/vnykmshr/goflow/pkg/ratelimit/bucket"
"github.com/vnykmshr/goflow/pkg/scheduling/workerpool"
"github.com/vnykmshr/goflow/pkg/scheduling/scheduler"
)
func main() {
limiter, err := bucket.NewSafe(10, 20) // 10 RPS, burst 20
if err != nil {
log.Fatal(err)
}
pool, err := workerpool.NewWithConfigSafe(workerpool.Config{
WorkerCount: 5,
QueueSize: 100,
TaskTimeout: 30 * time.Second,
})
if err != nil {
log.Fatal(err)
}
defer func() { <-pool.Shutdown() }()
if limiter.Allow() {
task := workerpool.TaskFunc(func(ctx context.Context) error {
fmt.Println("Processing request...")
return nil
})
if err := pool.Submit(task); err != nil {
log.Printf("Failed to submit task: %v", err)
}
}
}Rate Limiters
bucket.NewSafe(rate, burst)- Token bucket with burst capacityleakybucket.New(rate)- Smooth rate limitingconcurrency.NewSafe(limit)- Concurrent operations control
Scheduling
workerpool.NewSafe(workers, queueSize)- Background task processingscheduler.New()- Cron and interval scheduling
Streaming
stream.FromSlice(data)- Functional data processingwriter.New(config)- Async buffered writing
make install-hooks # Install pre-commit hook
make test # Run tests with race detection
make lint # Run linter
make benchmark # Run performance benchmarksThe pre-commit hook automatically:
- Checks for potential secrets
- Formats Go code with
goimportsandgofmt - Runs
golangci-linton changed files - Verifies the build succeeds
See Contributing for contribution guidelines.
MIT License - see LICENSE for details.