An open API service indexing awesome lists of open source software.

https://github.com/gozephyr/transportx

๐Ÿš€ 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! ๐Ÿ“Šโšก๐Ÿ”„
https://github.com/gozephyr/transportx

buffer dns go golang grpc http pool protobuf trasport

Last synced: about 2 months ago
JSON representation

๐Ÿš€ 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! ๐Ÿ“Šโšก๐Ÿ”„

Awesome Lists containing this project

README

          

# TransportX ๐Ÿš€

[![Go Reference](https://pkg.go.dev/badge/github.com/gozephyr/transportx.svg)](https://pkg.go.dev/github.com/gozephyr/transportx)
[![Go Report Card](https://goreportcard.com/badge/github.com/gozephyr/transportx)](https://goreportcard.com/report/github.com/gozephyr/transportx)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Build Status](https://github.com/gozephyr/transportx/actions/workflows/go.yml/badge.svg)](https://github.com/gozephyr/transportx/actions/workflows/go.yml)
[![Coverage Status](https://img.shields.io/codecov/c/github/gozephyr/transportx?label=coverage)](https://app.codecov.io/gh/gozephyr/transportx)

**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

```bash
go get github.com/gozephyr/transportx
```

---

## ๐Ÿš€ Quick Start

### ๐ŸŒ HTTP Example

```go
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

```go
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:**

```go
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:**

```go
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

- [GoDoc Reference](https://pkg.go.dev/github.com/gozephyr/transportx)

- [API & Extension Guide](./docs/)

---

## ๐Ÿ“ License

TransportX is licensed under the MIT License.