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! ๐โก๐
- Host: GitHub
- URL: https://github.com/gozephyr/transportx
- Owner: gozephyr
- License: mit
- Created: 2025-05-30T12:15:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-12-16T05:50:53.000Z (6 months ago)
- Last Synced: 2025-12-19T17:16:43.661Z (6 months ago)
- Topics: buffer, dns, go, golang, grpc, http, pool, protobuf, trasport
- Language: Go
- Homepage:
- Size: 106 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TransportX ๐
[](https://pkg.go.dev/github.com/gozephyr/transportx)
[](https://goreportcard.com/report/github.com/gozephyr/transportx)
[](LICENSE)
[](https://github.com/gozephyr/transportx/actions/workflows/go.yml)
[](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.