Skip to content

πŸš€ TransportX - High-performance, extensible Go transport layer library with unified API for HTTP, gRPC, and future protocols. Features advanced connection pooling, built-in metrics, robust error handling, and easy protocol extensibility. Perfect for microservices and distributed systems! πŸ“Šβš‘πŸ”„

License

Notifications You must be signed in to change notification settings

gozephyr/transportx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TransportX πŸš€

Go Reference Go Report Card License: MIT Build Status Coverage Status

TransportX is a high-performance, extensible transport layer library for Go. It provides a unified, user-friendly interface for multiple transport protocols (HTTP, gRPC, and more), designed to be faster and more efficient than the standard Go transport packages while maintaining simplicity and ease of use.


✨ Features

  • πŸš€ Unified API for HTTP, gRPC, and future protocols
  • 🧩 Extensible: Add your own protocols easily
  • πŸ“Š Built-in metrics and observability
  • πŸ›‘οΈ Production-ready: Robust connection pooling, DNS, and error handling
  • πŸ”’ Security: TLS and authentication support (where applicable)
  • πŸ§ͺ Tested: Includes examples and stress tests

πŸ’‘ Why Use TransportX?

TransportX is designed for developers who want a robust, flexible, and high-performance way to handle network communication in Go. It abstracts away the complexity of managing different transport protocols, connection pooling, retries, and observability, letting you focus on your business logic. Whether you're building microservices, distributed systems, or high-throughput applications, TransportX provides a consistent and extensible API for all your transport needs.

🌟 Key Benefits

  • πŸ”„ Unified API: Switch between HTTP, gRPC, and other protocols with minimal code changes.
  • πŸ” Advanced Connection Management: Built-in pooling, retries, timeouts, and health checks.
  • ⚑ Performance: Optimized for throughput and latency, with support for HTTP/2 and efficient batching.
  • πŸ“ˆ Observability: Built-in metrics for latency, throughput, errors, and connection state.
  • 🧱 Extensibility: Easily add support for new protocols.
  • 🧹 Cleaner Code: Focus on your application logic, not low-level networking details.

πŸ“Š Summary Comparison Table

🚦 Feature/Benefit 🌐 net/http (std) πŸ”— gRPC (std) πŸš€ TransportX
Unified API (multi-proto) ❌ ❌ βœ…
Connection Pooling Basic/Manual βš™οΈ Built-in πŸ—οΈ Advanced πŸš€
Retries/Timeouts Manual/Basic ⏱️ Basic ⏱️ Advanced πŸ”
Metrics/Observability ❌ Partial πŸ“‰ βœ…
Protocol Extensibility ❌ ❌ βœ…
Batching Support ❌ Partial πŸ“¦ βœ…
Health Checks ❌ Partial 🩺 βœ…
Easy Config Management Manual πŸ“ Manual πŸ“ βœ…
Future Protocols (WebSocket, QUIC, etc.) ❌ ❌ βœ… (planned)

Legend:

  • βœ… = Fully supported or built-in
  • ❌ = Not supported or requires significant manual work
  • Partial = Some support, but not unified or requires extra setup
  • Emojis indicate special features or manual effort

πŸ“¦ Installation

go get github.com/gozephyr/transportx

πŸš€ Quick Start

🌍 HTTP Example

package main

import (
    "context"
    "fmt"
    "github.com/gozephyr/transportx"
)

func main() {
    // Create a default HTTP config and customize as needed
    cfg := transportx.DefaultHTTPConfig()
    cfg.ServerAddress = "localhost"
    cfg.Port = 8080

    // Create a unified client
    client, err := transportx.NewClient(transportx.TypeHTTP, cfg)
    if err != nil {
        panic(err)
    }
    defer client.Disconnect(context.Background())

    // Connect and send a request
    ctx := context.Background()
    if err := client.Connect(ctx); err != nil {
        panic(err)
    }
    resp, err := client.Send(ctx, []byte("Hello, server!"))
    if err != nil {
        panic(err)
    }
    fmt.Println("Response:", string(resp))
}

⚑ gRPC Example

package main

import (
    "context"
    "fmt"
    "github.com/gozephyr/transportx"
)

func main() {
    cfg := transportx.DefaultGRPCConfig()
    cfg.ServerAddress = "localhost"
    cfg.Port = 50051

    client, err := transportx.NewClient(transportx.TypeGRPC, cfg)
    if err != nil {
        panic(err)
    }
    defer client.Disconnect(context.Background())

    ctx := context.Background()
    if err := client.Connect(ctx); err != nil {
        panic(err)
    }
    resp, err := client.Send(ctx, []byte("Hello, gRPC server!"))
    if err != nil {
        panic(err)
    }
    fmt.Println("gRPC Response:", string(resp))
}

🧰 HTTP Helpers (helper/http)

TransportX provides additional helpers for seamless integration with the Go standard library and idiomatic HTTP workflows:

HTTPAdapter

  • What: Wraps your business logic as a net/http handler using a simple, testable function signature.
  • Why: Decouples your core logic from HTTP details, reduces boilerplate, and makes your code reusable across frameworks.
  • How:
import (
    "net/http"
    helperhttp "github.com/gozephyr/transportx/helper/http"
)

func MyLogic(ctx context.Context, data []byte) ([]byte, error) {
    // Your business logic here
    return []byte("Hello from server!"), nil
}

func main() {
    http.HandleFunc("/api", helperhttp.HTTPAdapter(MyLogic))
    http.ListenAndServe(":8080", nil)
}

TransportxRoundTripper

  • What: A drop-in replacement for http.RoundTripper that uses TransportX's HTTP transport.
  • Why: Lets you use custom TransportX features (metrics, batching, retries, etc.) with any http.Client.
  • How:
import (
    "net/http"
    "bytes"
    txhttp "github.com/gozephyr/transportx/protocols/http"
    helperhttp "github.com/gozephyr/transportx/helper/http"
)

func main() {
    cfg := txhttp.NewConfig().WithServerAddress("example.com").WithPort(8080)
    transport, err := txhttp.NewHTTPTransport(cfg)
    if err != nil {
        panic(err)
    }
    rt := helperhttp.NewTransportxRoundTripper(transport.(*txhttp.HTTPTransport))
    client := &http.Client{Transport: rt}
    resp, err := client.Post("http://example.com", "application/json", bytes.NewReader([]byte(`{"foo":"bar"}`)))
    // ... handle resp and err ...
}

Benefits:

  • Plug-and-play with any code using http.Client or net/http handlers
  • Enables custom TransportX features in standard Go HTTP workflows
  • Makes business logic easy to test and reuse
  • Foundation for adapters for other frameworks (Gin, Fiber, etc.)

βš™οΈ Configuration Options

🌍 HTTP Config (DefaultHTTPConfig())

Field Type Default Description
Protocol string "http" Protocol scheme ("http" or "https")
ServerAddress string "localhost" Hostname or IP
Port int 8080 Server port
MaxIdleConns int 100 Max idle connections
MaxConnsPerHost int 100 Max connections per host
IdleTimeout time.Duration 90s Idle connection timeout
KeepAlive time.Duration 30s Keep-alive duration
ResponseTimeout time.Duration 30s Response timeout
MaxWaitDuration time.Duration 5s Max wait for connection
HealthCheckDelay time.Duration 30s Health check delay
EnableHTTP2 bool true Enable HTTP/2
MaxHeaderBytes int 32*1024 Max header bytes
DisableCompression bool false Disable compression
DisableKeepAlives bool false Disable keep-alives

⚑ gRPC Config (DefaultGRPCConfig())

Field Type Default Description
ServerAddress string "localhost" Hostname or IP
Port int 50051 Server port
Timeout time.Duration 30s Operation timeout
MaxRetries int 3 Max retries
MaxConcurrentStreams uint32 100 Max concurrent streams
InitialWindowSize int32 1MB Initial window size
MaxHeaderListSize uint32 8192 Max header list size
KeepAliveTime time.Duration 30s Keep-alive ping interval
KeepAliveTimeout time.Duration 10s Keep-alive timeout
TLSConfig *TLSConfig nil TLS configuration (see below)
DialOptions []DialOption nil Additional gRPC dial options

🧭 Protocol Support Matrix

Protocol Status Notes
🌍 HTTP βœ… Stable Full client support
⚑ gRPC βœ… Stable Full client support
πŸ”Œ TCP 🚧 Planned Not yet implemented
πŸ“‘ UDP 🚧 Planned Not yet implemented
🌐 WebSocket 🚧 Planned Not yet implemented
🏎️ QUIC 🚧 Planned Not yet implemented
πŸ“» MQTT 🚧 Planned Not yet implemented
βœ‰οΈ AMQP 🚧 Planned Not yet implemented

πŸ› οΈ Extending TransportX

TransportX is designed for extensibility. To add a new protocol:

  1. Implement the relevant interface(s) from protocols/ (e.g., Protocol, StreamProtocol, BatchProtocol, PubSubProtocol).
  2. Provide a config struct and builder.
  3. Register your protocol in the core package (see transportx.go).
  4. Add tests and examples.

πŸ“š Further Documentation


πŸ“ License

TransportX is licensed under the MIT License.

About

πŸš€ TransportX - High-performance, extensible Go transport layer library with unified API for HTTP, gRPC, and future protocols. Features advanced connection pooling, built-in metrics, robust error handling, and easy protocol extensibility. Perfect for microservices and distributed systems! πŸ“Šβš‘πŸ”„

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •