Skip to content

go-zoox/zoox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Zoox - A Lightweight, High Performance Go Web Framework

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release Go Version License

Zoox is a modern, lightweight, and high-performance web framework for Go. It provides a comprehensive set of features for building robust web applications, APIs, and microservices with excellent developer experience.

✨ Features

πŸš€ Core Features

  • Lightweight & Fast: Minimal overhead with high performance
  • Type-Safe: Full Go type safety with excellent IDE support
  • Middleware Support: Rich ecosystem of built-in middleware
  • Router: Fast trie-based router with parameter support
  • Context: Enhanced HTTP context with utilities
  • Templates: Built-in template engine with custom functions

πŸ”§ Built-in Components

  • Cache: Redis and in-memory caching support
  • Session: Secure session management
  • JWT: JSON Web Token authentication
  • CORS: Cross-Origin Resource Sharing
  • Rate Limiting: Request rate limiting
  • WebSocket: Real-time communication
  • JSON-RPC: JSON-RPC server support
  • Pub/Sub: Event-driven messaging
  • Message Queue: Asynchronous message processing
  • Cron Jobs: Scheduled task execution
  • Job Queue: Background job processing
  • i18n: Internationalization support
  • Logger: Structured logging
  • Monitoring: Prometheus metrics
  • Debug: Development debugging tools

πŸ›‘οΈ Security & Performance

  • Helmet: Security headers middleware
  • Gzip: Response compression
  • Body Limit: Request size limiting
  • Timeout: Request timeout handling
  • Recovery: Panic recovery
  • Real IP: Client IP detection
  • Request ID: Request tracing
  • Sentry: Error tracking integration

πŸ“¦ Installation

go get github.com/go-zoox/zoox

πŸš€ Quick Start

Basic Example

package main

import "github.com/go-zoox/zoox"

func main() {
    app := zoox.Default()

    app.Get("/", func(ctx *zoox.Context) {
        ctx.JSON(zoox.H{
            "message": "Hello, Zoox!",
            "version": zoox.Version,
        })
    })

    app.Get("/users/:id", func(ctx *zoox.Context) {
        id := ctx.Param("id")
        ctx.JSON(zoox.H{
            "id":   id,
            "name": "John Doe",
        })
    })

    app.Run(":8080")
}

Advanced Example with Middleware

package main

import (
    "github.com/go-zoox/zoox"
    "github.com/go-zoox/zoox/middleware"
)

func main() {
    app := zoox.New()

    // Global middleware
    app.Use(middleware.Logger())
    app.Use(middleware.Recovery())
    app.Use(middleware.CORS())
    app.Use(middleware.Gzip())

    // API routes
    api := app.Group("/api/v1")
    api.Use(middleware.Jwt())

    api.Get("/users", func(ctx *zoox.Context) {
        ctx.JSON(zoox.H{
            "users": []zoox.H{
                {"id": 1, "name": "Alice"},
                {"id": 2, "name": "Bob"},
            },
        })
    })

    api.Post("/users", func(ctx *zoox.Context) {
        var user struct {
            Name  string `json:"name"`
            Email string `json:"email"`
        }
        
        if err := ctx.BindJSON(&user); err != nil {
            ctx.Error(400, "Invalid JSON")
            return
        }

        ctx.JSON(zoox.H{
            "message": "User created",
            "user":    user,
        })
    })

    app.Run(":8080")
}

πŸ› οΈ Development Tools

Install the Zoox CLI for enhanced development experience:

go install github.com/go-zoox/zoox/cmd/zoox@latest

CLI Commands

# Start development server with hot reload
zoox dev

# Build application for production
zoox build

# Run tests
zoox test

# Generate API documentation
zoox docs

πŸ“š Documentation

Middleware

Zoox provides a rich set of middleware for common web application needs:

// Authentication
app.Use(middleware.Jwt())
app.Use(middleware.BasicAuth("Protected Area", map[string]string{
    "admin": "password",
}))
app.Use(middleware.BearerToken("token"))

// Security
app.Use(middleware.Helmet(nil))
app.Use(middleware.CORS())
app.Use(middleware.RateLimit(&middleware.RateLimitConfig{
    Period: time.Minute,
    Limit:  100,
}))

// Performance
app.Use(middleware.Gzip())
app.Use(middleware.CacheControl(&middleware.CacheControlConfig{
    Paths:  []string{".*"},
    MaxAge: time.Hour,
}))

// Monitoring
app.Use(middleware.Prometheus())
app.Use(middleware.Logger())
app.Use(middleware.RequestID())

// Development
app.Use(middleware.PProf())

Context Utilities

func handler(ctx *zoox.Context) {
    // Request data
    body := ctx.Body()
    query := ctx.Query().Get("page")
    param := ctx.Param().Get("id")
    header := ctx.Header().Get("Authorization")
    
    // Form data
    form := ctx.Form().Get("name")
    file, fileHeader, err := ctx.File("upload")
    
    // JSON handling
    var data map[string]interface{}
    ctx.BindJSON(&data)
    
    // Response
    ctx.JSON(200, zoox.H{"status": "success"})
    ctx.HTML(200, "template.html", data)
    ctx.RenderStatic("/static/", "static/")
    
    // Status codes
    ctx.Status(201)
    ctx.Error(400, "Bad Request")
}

Database Integration

// Cache example
cache := app.Cache()
cache.Set("key", "value", time.Hour)
value := cache.Get("key")

// Session example
session := ctx.Session()
session.Set("user_id", 123)
userID := session.Get("user_id")

WebSocket Support

server, err := app.WebSocket("/ws")
if err != nil {
    log.Fatal(err)
}

server.OnMessage(func(message []byte) {
    server.WriteText("Echo: " + string(message))
})

Scheduled Tasks

cron := app.Cron()
cron.AddJob("daily-cleanup", "0 0 * * *", func() error {
    // Daily task at midnight
    log.Println("Running daily cleanup")
    return nil
})

πŸ”§ Configuration

Zoox supports flexible configuration through environment variables and config files:

app := zoox.New()

// Environment-based configuration
app.Config.Protocol = "https"
app.Config.Host = "0.0.0.0"
app.Config.Port = 8443
app.Config.SecretKey = "your-secret-key"

// Redis configuration
app.Config.Redis.Host = "localhost"
app.Config.Redis.Port = 6379
app.Config.Redis.Password = "password"

// Session configuration
app.Config.Session.MaxAge = time.Hour

πŸ§ͺ Testing

func TestUserAPI(t *testing.T) {
    app := zoox.New()
    
    app.Get("/users/:id", func(ctx *zoox.Context) {
        id := ctx.Param().Get("id")
        ctx.JSON(200, zoox.H{"id": id.String()})
    })

    req := httptest.NewRequest("GET", "/users/123", nil)
    w := httptest.NewRecorder()
    
    app.ServeHTTP(w, req)
    
    assert.Equal(t, 200, w.Code)
    assert.Contains(t, w.Body.String(), `"id":"123"`)
}

πŸ“Š Performance

Zoox is designed for high performance:

  • Fast Router: Trie-based routing with O(1) lookup
  • Minimal Memory: Low memory footprint
  • Concurrent Safe: Thread-safe design
  • Zero Allocations: Optimized for minimal GC pressure

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

git clone https://github.com/go-zoox/zoox.git
cd zoox
go mod download
go test ./...

πŸ“„ License

Zoox is released under the MIT License.

πŸ™ Acknowledgments

  • Inspired by modern web frameworks
  • Built with Go's standard library
  • Community-driven development

πŸ“ž Support


Made with ❀️ by the Zoox Team

About

A Lightweight Web Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages