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.
- π 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
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.
- π 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.
| π¦ 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
go get github.com/gozephyr/transportxpackage 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))
}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))
}TransportX provides additional helpers for seamless integration with the Go standard library and idiomatic HTTP workflows:
- What: Wraps your business logic as a
net/httphandler 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)
}- What: A drop-in replacement for
http.RoundTripperthat 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.Clientornet/httphandlers - 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.)
| 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 |
| 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 | 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 |
TransportX is designed for extensibility. To add a new protocol:
- Implement the relevant interface(s) from
protocols/(e.g.,Protocol,StreamProtocol,BatchProtocol,PubSubProtocol). - Provide a config struct and builder.
- Register your protocol in the core package (see
transportx.go). - Add tests and examples.
TransportX is licensed under the MIT License.