Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍹 Slurpy

A vibe coded POC to try to get a network tab for CLI app

Go Version License

✨ Features

πŸ”§ Slurpy SDK

  • Drop-in replacement for Go's standard HTTP client
  • Automatic logging of requests and responses
  • Namespace support for organizing logs by project/service
  • Zero-overhead when disabled
  • Request/response body capture with automatic restoration
  • Duration tracking for performance analysis
  • Error handling and logging

🎨 Slurpy CLI

  • Beautiful TUI built with Bubble Tea
  • Two-panel layout similar to browser dev tools
  • Request filtering and search capabilities
  • Detailed request/response inspection
  • Namespace-based filtering
  • Keyboard navigation for efficiency
  • Color-coded status indicators

πŸš€ Quick Start

Installation

go get github.com/bobby/slurpy

Basic Usage

package main

import (
    "log"
    "github.com/bobby/slurpy/sdk"
)

func main() {
    // Create client with logging enabled
    client, err := slurpy.New(slurpy.Config{
        Namespace: "my-app",
        Enabled:   true,
    })
    if err != nil {
        log.Fatal(err)
    }

    // Use like any HTTP client - requests are automatically logged
    resp, err := client.Get("https://api.example.com/users")
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()

    // Request is now logged to ~/.config/slurpy/logs/
}

Launch the CLI

# Build and run
go build -o slurpy ./cli
./slurpy

# Or use the Makefile
make cli

πŸ“– Documentation

SDK Configuration

type Config struct {
    Namespace string // Unique identifier for this project
    Enabled   bool   // Enable/disable logging
}

Default namespace: "default"
Storage location: ~/.config/slurpy/logs/

Supported HTTP Methods

The Slurpy client implements all standard HTTP methods:

// Standard methods
resp, err := client.Get(url)
resp, err := client.Post(url, contentType, body)
resp, err := client.Put(url, contentType, body)
resp, err := client.Delete(url)

// Custom requests
resp, err := client.Do(req)

Runtime Configuration

// Change namespace dynamically
client.SetNamespace("new-service")

// Toggle logging on/off
client.SetEnabled(false) // Disable logging
client.SetEnabled(true)  // Re-enable logging

// Check current state
namespace := client.GetNamespace()
enabled := client.IsEnabled()

Advanced Usage

// Multiple clients with different namespaces
userClient, _ := slurpy.New(slurpy.Config{
    Namespace: "user-service",
    Enabled:   true,
})

paymentClient, _ := slurpy.New(slurpy.Config{
    Namespace: "payment-service", 
    Enabled:   true,
})

// Custom requests with headers
req, _ := http.NewRequest("GET", "https://api.example.com/data", nil)
req.Header.Set("Authorization", "Bearer token")
req.Header.Set("X-API-Key", "secret")

resp, err := client.Do(req)

πŸ–₯️ CLI Usage

Key Bindings

Key Action
↑/k, ↓/j Navigate request list
tab Switch between panels
r Refresh requests
c Clear current namespace
? Toggle help
q/esc Quit

Interface

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Request List         β”‚      Request Details        β”‚
β”‚                             β”‚                             β”‚
β”‚ ● GET /api/users [200]      β”‚ REQUEST                     β”‚
β”‚   10:30:45 β€’ 45ms β€’ my-app  β”‚ Method: GET                 β”‚
β”‚                             β”‚ URL: https://api.../users   β”‚
β”‚ ● POST /api/users [201]     β”‚ Duration: 45ms              β”‚
β”‚   10:30:50 β€’ 123ms β€’ my-app β”‚                             β”‚
β”‚                             β”‚ Request Headers:            β”‚
β”‚ ● PUT /api/users/1 [200]    β”‚   Authorization: Bearer ... β”‚
β”‚   10:31:15 β€’ 67ms β€’ my-app  β”‚   Content-Type: application β”‚
β”‚                             β”‚                             β”‚
β”‚                             β”‚ RESPONSE                    β”‚
β”‚                             β”‚ Status: 200                 β”‚
β”‚                             β”‚ Size: 1234 bytes            β”‚
β”‚                             β”‚                             β”‚
β”‚                             β”‚ Response Body:              β”‚
β”‚                             β”‚ {"users": [...]}            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

  • Request List (Left Panel): Shows all HTTP requests with method, URL, status, and timing
  • Request Details (Right Panel): Detailed view of headers, body, and response data
  • Filtering: Built-in search and filter capabilities
  • Color Coding: Visual status indicators (green=success, red=error, yellow=pending)
  • Namespace Organization: Requests grouped by service/project namespace

πŸ—οΈ Architecture

slurpy/
β”œβ”€β”€ pkg/           # Shared data structures and utilities
β”‚   β”œβ”€β”€ models/    # Request/response models
β”‚   └── storage/   # File system storage management
β”œβ”€β”€ sdk/           # Slurpy SDK for Go applications
β”œβ”€β”€ cli/           # Bubble Tea TUI application
β”‚   └── ui/        # UI components and styling
β”œβ”€β”€ examples/      # Usage examples
β”‚   β”œβ”€β”€ basic/     # Simple usage example
β”‚   └── advanced/  # Advanced features demo
β”œβ”€β”€ Makefile       # Build and development commands
└── test_slurpy.go # Comprehensive test suite

πŸ’Ύ Storage Format

Requests are stored as JSON files in ~/.config/slurpy/logs/ with the naming convention:

{namespace}_{request_id}.json

Data Structure

{
  "id": "abc123def456",
  "timestamp": "2024-01-15T10:30:00Z",
  "method": "GET",
  "url": "https://api.example.com/users",
  "headers": {"Authorization": "Bearer token"},
  "body": "",
  "response": {
    "status_code": 200,
    "headers": {"Content-Type": "application/json"},
    "body": "{\"users\": []}",
    "size": 123
  },
  "duration": "45ms",
  "namespace": "my-app",
  "error": ""
}

πŸ› οΈ Development

Available Commands

# Development
make build       # Build the CLI
make cli         # Build and run CLI
make example     # Run basic example to generate test data
make run-example # Run example then start CLI
make deps        # Install dependencies

# Testing & Cleanup
make test        # Run tests
make clean       # Clean built artifacts and logs
make help        # Show available commands

Testing

# Run comprehensive test suite
go run test_slurpy.go

# Generate test data with examples
go run ./examples/basic
go run ./examples/advanced

Building

# Build CLI
go build -o slurpy ./cli

# Build for different platforms
GOOS=linux GOARCH=amd64 go build -o slurpy-linux ./cli
GOOS=windows GOARCH=amd64 go build -o slurpy.exe ./cli

πŸ“š Examples

Basic Integration

See examples/basic/main.go for a simple integration example.

Advanced Features

See examples/advanced/main.go for:

  • Multiple namespaces
  • Runtime configuration changes
  • Custom headers and requests
  • CRUD operations
  • Error handling

Real-world Integration

// In your existing application
func NewHTTPClient() *http.Client {
    if debug {
        client, _ := slurpy.New(slurpy.Config{
            Namespace: "my-service",
            Enabled:   true,
        })
        return client.Client
    }
    return &http.Client{}
}

πŸ”§ Configuration

Environment Variables

While Slurpy doesn't use environment variables directly, you can integrate them:

client, err := slurpy.New(slurpy.Config{
    Namespace: os.Getenv("SERVICE_NAME"),
    Enabled:   os.Getenv("DEBUG") == "true",
})

Storage Location

Default: ~/.config/slurpy/logs/

To use a custom location, modify the storage package or implement your own storage backend.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Guidelines

  • Follow Go best practices and conventions
  • Add tests for new features
  • Update documentation as needed
  • Keep the CLI responsive and user-friendly
  • Maintain backward compatibility

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Bubble Tea - Amazing TUI framework
  • Lip Gloss - Beautiful styling
  • Bubbles - TUI components
  • Inspired by browser developer tools and network debugging needs

πŸ“ž Support


Happy debugging! 🍹✨

About

A vibe coded POC to try to get a network tab for CLI app

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages