A blazing-fast, production-ready web framework for Go that combines the performance of FastHTTP with the elegance of modern web frameworks like Axum and Actix Web.
Blaze delivers exceptional performance with enterprise-grade features:
Requests/sec: 190,376.62
Transfer/sec: 118.38MB
Latency: 527.70ΞΌs avg (Β±765.78ΞΌs)
Max Latency: 11.73ms
Memory Usage: Ultra-low footprint with intelligent caching
Requests/sec: 182,505.60
Transfer/sec: 83.20MB
Latency: 790.07ΞΌs avg (Β±1.04ms)
Max Latency: 11.99ms
Memory Usage: Ultra-low footprint
Benchmarked with wrk -c100 -d30s on production-grade endpoints with 100 concurrent connections over 30 seconds.
π― Cache Performance Boost:
- +4.3% throughput
- +42% data transfer
- -33% latency with built-in caching middleware.
- Lightning Fast: Built on FastHTTP - 190K+ req/sec with caching, 182K+ req/sec sustained throughput
- Intelligent Caching: Built-in cache middleware with LRU/LFU/FIFO/Random eviction strategies
- Zero-Copy: Optimized memory usage with minimal allocations
- HTTP/2 & h2c: Full HTTP/2 support with server push capabilities
- TLS/HTTPS: Auto-TLS, custom certificates, and development-friendly SSL
- Type Safety: Full compile-time type checking and validation with go-playground/validator
- Graceful Shutdown: Clean shutdown with connection draining and context awareness
- Middleware Stack: Composable middleware with CORS, CSRF, rate limiting, compression
- Error Handling: Comprehensive error handling with recovery and stack traces
- Struct-Based Binding: Bind multipart forms, JSON, and form data to structs with validation tags
- File Upload System: Single/multiple file uploads with validation and unique filename generation
- WebSockets: Real-time communication with connection management and broadcasting
- Static File Serving: Advanced configuration with caching, compression, ETag, and range requests
- Validation System: Integrated validation with automatic error formatting
- All HTTP Methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT, TRACE, ANY, Match
- Route Constraints: Integer, UUID, regex, and custom parameter validation
- Route Groups: Organized API versioning with shared middleware
- Configuration Profiles: Environment-specific configs (dev, staging, production)
- Comprehensive Context: Rich request/response handling with locals, timeouts, and shutdown awareness
go get github.com/AarambhDevHub/blazepackage main
import (
"log"
"github.com/AarambhDevHub/blaze/pkg/blaze"
)
func main() {
app := blaze.New()
app.GET("/", func(c *blaze.Context) error {
return c.JSON(blaze.Map{
"message": "Hello, Blaze! π₯",
"status": "success",
"version": "v0.1.4",
})
})
// Route with validation
type User struct {
Name string `json:"name" validate:"required,min=2,max=100"`
Email string `json:"email" validate:"required,email"`
Age int `json:"age" validate:"gte=18,lte=100"`
}
app.POST("/users", func(c *blaze.Context) error {
var user User
// Bind and validate in one call
if err := c.BindJSONAndValidate(&user); err != nil {
return c.Status(400).JSON(blaze.Map{"error": err.Error()})
}
return c.Status(201).JSON(user)
})
log.Printf("π₯ Blaze server starting on http://localhost:8080")
log.Fatal(app.ListenAndServeGraceful())
}func main() {
// Production-ready configuration
config := blaze.ProductionConfig()
config.Host = "0.0.0.0"
config.Port = 80
config.TLSPort = 443
config.EnableHTTP2 = true
config.EnableTLS = true
app := blaze.NewWithConfig(config)
// Enable auto-TLS
app.EnableAutoTLS("yourdomain.com", "www.yourdomain.com")
// Production middleware stack
app.Use(blaze.Recovery())
app.Use(blaze.LoggerMiddleware())
app.Use(blaze.RequestIDMiddleware())
app.Use(blaze.CORS(blaze.CORSOptions{
AllowOrigins: []string{"https://yourdomain.com"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
}))
app.Use(blaze.CSRF(blaze.ProductionCSRFOptions([]byte("secret"))))
app.Use(blaze.RateLimitMiddleware(blaze.RateLimitOptions{
MaxRequests: 1000,
Window: time.Hour,
}))
app.Use(blaze.CompressWithLevel(blaze.CompressionLevelBest))
app.Use(blaze.Cache(blaze.ProductionCacheOptions()))
// Your routes...
log.Fatal(app.ListenAndServeGraceful(syscall.SIGINT, syscall.SIGTERM))
}app := blaze.New()
// Standard RESTful routes
app.GET("/users", getUsers) // List users
app.POST("/users", createUser) // Create user
app.GET("/users/:id", getUser) // Get user by ID
app.PUT("/users/:id", updateUser) // Update user
app.DELETE("/users/:id", deleteUser) // Delete user
app.PATCH("/users/:id", patchUser) // Partial update
app.HEAD("/users/:id", checkUser) // Headers only
app.OPTIONS("/users", optionsUsers) // CORS preflight
// Extended HTTP methods
app.CONNECT("/tunnel/:target", tunnelHandler) // Tunnel connections
app.TRACE("/debug", traceHandler) // Request tracing
// ANY route (handles all methods)
app.ANY("/api/health", func(c *blaze.Context) error {
return c.JSON(blaze.Map{
"status": "healthy",
"method": c.Method(),
})
})
// Match specific methods
app.Match([]string{"GET", "POST", "PUT"}, "/api/data", dataHandler)
// Route parameters with constraints
app.GET("/users/:id", getUserHandler,
blaze.WithIntConstraint("id"))
app.GET("/items/:uuid", getItemHandler,
blaze.WithUUIDConstraint("uuid"))
app.GET("/products/:sku", getProductHandler,
blaze.WithRegexConstraint("sku", `^[A-Z]{2}-\d{4}$`))
// Wildcards
app.GET("/static/*filepath", serveStatic)type UserProfile struct {
Name string `form:"name,required,minsize:2,maxsize:100"`
Email string `form:"email,required"`
Age int `form:"age,required,default:18"`
Avatar *blaze.MultipartFile `form:"avatar"`
IsActive bool `form:"is_active"`
Bio string `form:"bio,maxsize:500"`
JoinedAt *time.Time `form:"joined_at"`
Tags []string `form:"tags"`
}
app.POST("/profile", func(c *blaze.Context) error {
var profile UserProfile
// Automatic form binding with validation
if err := c.BindMultipartFormAndValidate(&profile); err != nil {
return c.Status(400).JSON(blaze.Map{"error": err.Error()})
}
// Save avatar if uploaded
if profile.Avatar != nil {
savedPath, err := c.SaveUploadedFileWithUniqueFilename(profile.Avatar, "uploads/")
if err != nil {
return c.Status(500).JSON(blaze.Map{"error": "Failed to save avatar"})
}
log.Printf("Avatar saved: %s", savedPath)
}
return c.JSON(blaze.Map{
"message": "Profile created successfully",
"profile": profile,
})
})type ChatHub struct {
clients map[*blaze.WebSocketConnection]bool
broadcast chan []byte
register chan *blaze.WebSocketConnection
unregister chan *blaze.WebSocketConnection
}
hub := NewChatHub()
go hub.Run()
app.WebSocket("/ws/chat", func(ws *blaze.WebSocketConnection) error {
hub.register <- ws
defer func() { hub.unregister <- ws }()
for {
_, message, err := ws.ReadMessage()
if err != nil {
break
}
hub.broadcast <- message
}
return nil
})// Global middleware with all features
app.Use(blaze.Recovery()) // Panic recovery with stack traces
app.Use(blaze.LoggerMiddlewareWithConfig(logConfig)) // Configurable logging
app.Use(blaze.RequestIDMiddleware()) // Unique request IDs
app.Use(blaze.CORS(corsOpts)) // CORS with fine-grained control
app.Use(blaze.CSRF(csrfOpts)) // CSRF protection
app.Use(blaze.RateLimitMiddleware(rateOpts)) // Rate limiting per IP
app.Use(blaze.BodyLimitMB(10)) // Request body size limits
app.Use(blaze.CompressWithLevel(9)) // Gzip/Deflate/Brotli compression
app.Use(blaze.Cache(cacheOpts)) // LRU/LFU/FIFO/Random caching
app.Use(blaze.ShutdownAware()) // Graceful shutdown support
// Route-specific middleware
app.GET("/protected", protectedHandler,
blaze.WithMiddleware(authMiddleware),
blaze.WithMiddleware(rateLimitMiddleware))// API v1 with shared middleware
v1 := app.Group("/api/v1")
v1.Use(blaze.LoggerMiddleware())
v1.Use(blaze.Auth(tokenValidator))
v1.Use(blaze.RateLimitMiddleware(rateLimitOpts))
v1.GET("/users", listUsers)
v1.POST("/users", createUser)
v1.GET("/users/:id", getUser, blaze.WithIntConstraint("id"))
// Admin nested group
admin := v1.Group("/admin")
admin.Use(RequireAdminMiddleware())
admin.GET("/stats", getAdminStats)
admin.POST("/users/:id/ban", banUser)
admin.ANY("/system/*path", adminSystemHandler)
// API v2 with different structure
v2 := app.Group("/api/v2")
v2.Use(authMiddleware)
v2.Use(validationMiddleware)
v2.GET("/profiles", getProfiles)
v2.CONNECT("/stream/:id", streamConnection)
v2.TRACE("/debug/:session", debugSession)// Configure multipart handling
multipartConfig := blaze.ProductionMultipartConfig()
multipartConfig.MaxFileSize = 10 << 20 // 10MB
multipartConfig.MaxFiles = 5
multipartConfig.AllowedExtensions = []string{".jpg", ".png", ".pdf"}
app.Use(blaze.MultipartMiddleware(multipartConfig))
// Single file upload with validation
app.POST("/upload", func(c *blaze.Context) error {
file, err := c.FormFile("document")
if err != nil {
return c.Status(400).JSON(blaze.Map{"error": "No file uploaded"})
}
// Validate file type
if !file.IsDocument() {
return c.Status(400).JSON(blaze.Map{"error": "Only documents allowed"})
}
// Save with unique filename
path, err := c.SaveUploadedFileWithUniqueFilename(file, "uploads/")
if err != nil {
return c.Status(500).JSON(blaze.Map{"error": "Save failed"})
}
return c.JSON(blaze.Map{
"filename": file.Filename,
"saved_path": path,
"size": file.Size,
"content_type": file.ContentType,
})
})
// Static file serving with advanced configuration
staticConfig := blaze.DefaultStaticConfig("./public")
staticConfig.Compress = true
staticConfig.CacheDuration = 24 * time.Hour
staticConfig.GenerateETag = true
staticConfig.ByteRange = true // Enable range requests
app.StaticFS("/static", staticConfig)
// File download with range support
app.GET("/download/:filename", func(c *blaze.Context) error {
filepath := "uploads/" + c.Param("filename")
if !c.FileExists(filepath) {
return c.Status(404).JSON(blaze.Map{"error": "File not found"})
}
// Stream file with range request support for videos
return c.StreamFile(filepath)
})// HTTP/2 configuration
config := blaze.ProductionConfig()
config.EnableHTTP2 = true
config.EnableTLS = true
app := blaze.NewWithConfig(config)
// Configure TLS
tlsConfig := &blaze.TLSConfig{
CertFile: "server.crt",
KeyFile: "server.key",
MinVersion: tls.VersionTLS12,
NextProtos: []string{"h2", "http/1.1"},
}
app.SetTLSConfig(tlsConfig)
// Configure HTTP/2
http2Config := &blaze.HTTP2Config{
Enabled: true,
MaxConcurrentStreams: 1000,
EnablePush: true,
}
app.SetHTTP2Config(http2Config)
// Server push example
app.GET("/", func(c *blaze.Context) error {
if c.IsHTTP2() {
// Push critical resources
c.PushResources(map[string]string{
"/static/app.css": "style",
"/static/app.js": "script",
"/static/logo.png": "image",
})
log.Printf("Processing on HTTP/2 stream %d", c.StreamID())
}
return c.HTML(`<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/static/app.css">
<script src="/static/app.js"></script>
</head>
<body><h1>HTTP/2 with Server Push!</h1></body>
</html>`)
})Blaze provides a comprehensive middleware ecosystem:
// Core Middleware
app.Use(blaze.Recovery()) // Panic recovery
app.Use(blaze.LoggerMiddleware()) // Request logging
app.Use(blaze.LoggerMiddlewareWithConfig(cfg)) // Configurable logging
// Security Middleware
app.Use(blaze.CORS(corsOpts)) // CORS handling
app.Use(blaze.CSRF(csrfOpts)) // CSRF protection
app.Use(blaze.Auth(tokenValidator)) // Authentication
app.Use(blaze.HTTP2Security()) // HTTP/2 security headers
// Performance Middleware
app.Use(blaze.Cache(cacheOpts)) // LRU/LFU/FIFO/Random cache
app.Use(blaze.Compress()) // Gzip compression
app.Use(blaze.CompressWithLevel(9)) // Custom compression level
app.Use(blaze.CompressTypes("text/html")) // Compress specific types
// Request Control Middleware
app.Use(blaze.BodyLimit(10*1024*1024)) // Body size limits
app.Use(blaze.BodyLimitMB(10)) // Body limit in MB
app.Use(blaze.RateLimitMiddleware(rateOpts)) // Rate limiting
app.Use(blaze.RequestIDMiddleware()) // Request ID generation
// Specialized Middleware
app.Use(blaze.ValidationMiddleware()) // Validation support
app.Use(blaze.MultipartMiddleware(config)) // Multipart form handling
app.Use(blaze.ShutdownAware()) // Graceful shutdown
app.Use(blaze.GracefulTimeout(30*time.Second)) // Request timeouts
app.Use(blaze.HTTP2Info()) // HTTP/2 protocol info
app.Use(blaze.StreamInfo()) // HTTP/2 stream debugging| Framework | Req/sec | Latency | Memory | HTTP/2 | Validation | Cache | Notes |
|---|---|---|---|---|---|---|---|
| Blaze (Cache) | 190K | 0.53ms | Ultra Low | β | β | β | +42% transfer, All features |
| Blaze | 182K | 0.79ms | Ultra Low | β | β | β | Production Ready |
| Fiber | 165K | 0.60ms | Low | β | β | β | FastHTTP-based |
| FastHTTP | 200K+ | 0.5ms | Very Low | β | β | β | Raw performance |
| Gin | 50K | 10ms | Medium | β | Limited | β | Most popular |
| Echo | 40K | 15ms | Medium | β | Limited | β | Minimalist |
| Chi | 35K | 20ms | Low | β | β | β | Lightweight router |
| Go stdlib | 17K | 30ms | Medium | β | β | β | Standard library |
π Performance Leader: Blaze delivers the best real-world performance with comprehensive features.
- β All HTTP methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT, TRACE
- β ANY route (handles all methods)
- β Match route (handles specific multiple methods)
- β
Named parameters with type conversion (
:param) - β
Wildcard parameters (
*param) - β Route constraints (int, UUID, regex, custom)
- β Route groups with shared middleware
- β Named routes with priorities and tags
- β Query parameter handling with defaults
- β JSON body binding with validation
- β Form data binding with validation
- β Multipart form binding with struct tags
- β Automatic validation with go-playground/validator
- β
Combined bind and validate methods (
BindAndValidate,BindJSONAndValidate,BindMultipartFormAndValidate) - β Single variable validation
- β Body size validation
- β Custom validators and struct-level validation
- β JSON responses with helpers (OK, Created, Error, Paginate)
- β HTML responses
- β Text responses
- β File serving and downloads
- β File streaming with range requests
- β Redirects (301, 302, 307, 308)
- β Custom status codes and headers
- β Chainable response methods
- β Logger with configurable options
- β Recovery with stack traces
- β CORS with fine-grained control
- β CSRF protection with tokens
- β Rate limiting (per IP or custom key)
- β Caching (LRU, LFU, FIFO, Random)
- β Compression (Gzip, Deflate, Brotli)
- β Body limits (global and per-route)
- β Authentication (token-based)
- β Request ID generation
- β Graceful shutdown awareness
- β HTTP/2 specific middleware
- β Single file uploads
- β Multiple file uploads
- β Struct-based multipart binding with validation
- β File validation (size, type, extension)
- β Unique filename generation
- β Static file serving with advanced configuration
- β Directory browsing (configurable)
- β ETag generation
- β Byte-range requests for video streaming
- β MIME type detection
- β Compression for static files
- β WebSocket upgrade
- β Message reading/writing (text, binary)
- β JSON message support
- β Connection management
- β Broadcasting with hub pattern
- β Ping/Pong support
- β Configurable timeouts and buffer sizes
- β Native HTTP/2 support
- β Server push (single and multiple resources)
- β Stream ID access
- β Protocol detection
- β h2c (HTTP/2 over cleartext)
- β Configurable stream limits
- β HTTP/2 specific middleware
- β TLS configuration (production and development)
- β Auto-generated self-signed certificates
- β CSRF protection with tokens
- β CORS configuration
- β Security headers
- β Directory traversal protection
- β Rate limiting
- β Body size limits
- β Input validation
- β Graceful shutdown with context awareness
- β Health check endpoints
- β Configuration profiles (dev, prod, custom)
- β Application state management
- β Request-scoped locals
- β Comprehensive error handling
- β Logging system
- β Request timeouts with shutdown awareness
- β Metrics and monitoring hooks
wrk -c100 -d30s http://localhost:3000/
Running 30s test @ http://localhost:3000/
2 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 527.70us 765.78us 11.73ms 89.78%
Req/Sec 95.69k 20.89k 134.42k 68.83%
5711615 requests in 30.00s, 3.47GB read
Requests/sec: 190376.62
Transfer/sec: 118.38MB
wrk -c100 -d30s http://localhost:3000/
Running 30s test @ http://localhost:3000/
2 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 790.07us 1.04ms 11.99ms 85.35%
Req/Sec 91.74k 19.41k 120.94k 48.33%
5475380 requests in 30.00s, 2.44GB read
Requests/sec: 182505.60
Transfer/sec: 83.20MB
FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o blaze-app
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/blaze-app .
COPY --from=builder /app/static ./static
EXPOSE 8080
CMD ["./blaze-app"]
apiVersion: apps/v1
kind: Deployment
metadata:
name: blaze-app
spec:
replicas: 3
selector:
matchLabels:
app: blaze-app
template:
metadata:
labels:
app: blaze-app
spec:
containers:
- name: blaze-app
image: your-registry/blaze-app:latest
ports:
- containerPort: 8080
env:
- name: ENV
value: "production"
- name: CACHE_ENABLED
value: "true"
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Comprehensive documentation is available in the /docs directory:
- Quick Start - Get started in minutes
- Configuration - Application configuration
- Routing - Advanced routing with all HTTP methods
- Handlers - Request handlers and patterns
- Middleware - Built-in and custom middleware
- Validation - Struct validation system
- File Handling - File uploads and multipart forms
- Static Files - Static file serving
- WebSockets - Real-time communication
- HTTP/2 - HTTP/2 configuration and features
- Examples - Complete application examples
We welcome contributions! Please see our Contributing Guide for details.
# Clone repository
git clone https://github.com/AarambhDevHub/blaze.git
cd blaze
# Install dependencies
go mod download
# Run tests
go test ./...
# Run benchmarks
go test -bench=. ./...
# Start development server
go run examples/basic/main.go
This project is licensed under the MIT License - see the LICENSE file for details.
If you find Blaze helpful, consider supporting its development:
AarambhDevHub - Building the future of Go web development
- π GitHub: @AarambhDevHub
- πΊ YouTube: AarambhDevHub
- π¬ Discord: Join our community
If Blaze has helped you build amazing applications:
- β Star this repository
- π¦ Share on social media
- π Write about your experience
- π€ Contribute to the project
Built with β€οΈ by Aarambh Dev Hub
Blaze - Where performance meets elegance in Go web development.