GoWindGoWind
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
  • Introduction

    • GoWind Framework
    • Framework Architecture
  • go-wind Core

    • go-wind Core Framework
    • App Lifecycle Management
    • Context Propagation
    • Transport Abstraction
    • Log Facade Interface
  • go-wind-plugins

    • go-wind-plugins Plugin Overview
    • Plugin Configuration System
    • Plugin Registration Mechanism (SPI)
    • Logging Adapter Plugins
    • Transport Protocol Plugins
    • Message Middleware Plugins
    • Encoding Plugins
    • Security and Authentication Plugins
    • Distributed Tracing Plugins
    • Cache Plugins
    • Object Storage Plugins (OSS)
    • Rate Limiting Plugins
    • Metrics Plugins
    • AI Plugins
    • Workflow Plugins
    • Database and Cache Plugins
    • Bootstrap Integration and Gateway Plugins
    • Compression and Serialization Plugins
    • Template Rendering and Validation Plugins
  • go-wind-bootstrap

    • go-wind-bootstrap: The Declarative Bootstrap
    • The Bootstrap Configuration System
    • The Bootstrap SPI Mechanism
    • Declarative Middleware Orchestration
    • Bootstrap Command-Line Integration
    • Bootstrap Practical Examples
  • go-wind-flow Workflow Engine

    • GoWind Flow Process Engine
  • Tutorials

    • Quick Start Tutorial
    • Custom Plugin Development Tutorial
    • Multi-Protocol Listening Tutorial
    • Framework Migration Guide

Transport Abstraction

The Transport module of go-wind defines a unified interface for the transport layer, supporting HTTP, gRPC, WebSocket, SSE, and many other protocols.

1. The Server Interface

// transport/server.go
type Server interface {
    // Start begins accepting connections. It must block until ctx is
    // canceled or an error occurs.
    Start(ctx context.Context) error
    // Stop performs a graceful shutdown. The passed-in ctx carries a
    // timeout deadline, which implementations should respect.
    Stop(ctx context.Context) error
    // Endpoint returns the actual listening address. When bound to ":0"
    // (an OS-assigned port), it must return the resolved real address
    // after Start has begun accepting connections, so the caller can
    // register it with the service registry.
    Endpoint() string
}

Any transport implementing this interface can be registered with the App.

2. Supported Protocols

Transport implementations are provided by adapters (following the interface above). Current status:

ProtocolAdapterTypical Scenario
HTTPgo-wind-bootstrap/transport/http ✅REST APIs
gRPCgo-wind-bootstrap/transport/grpc ✅Internal service calls
HTTP/3, GraphQL, SSE, WebSocket, TCP, UDP, KCP, Thrift, tRPC, WebTransportPlannedSee the Bootstrap supported-components list

For declarative configuration and middleware orchestration of the HTTP / gRPC adapters, see Declarative Middleware Orchestration.

3. Custom Transport

package mytransport

type Server struct {
    addr     string
    listener net.Listener
}

func NewServer(opts ...Option) *Server {
    s := &Server{addr: ":9090"}
    for _, opt := range opts {
        opt(s)
    }
    return s
}

// Start must block until ctx is canceled
func (s *Server) Start(ctx context.Context) error {
    ln, err := net.Listen("tcp", s.addr)
    if err != nil {
        return err
    }
    s.listener = ln

    errCh := make(chan error, 1)
    go func() {
        errCh <- s.serve() // accept loop
    }()

    select {
    case err := <-errCh:
        return err
    case <-ctx.Done():
        return nil
    }
}

func (s *Server) Stop(ctx context.Context) error {
    return s.listener.Close()
}

// When bound to ":0", it should return the resolved real address after Start
func (s *Server) Endpoint() string {
    return fmt.Sprintf("custom://%s", s.listener.Addr())
}

4. Listening on Multiple Protocols

app := wind.New(
    wind.WithServer(httpServer),    // HTTP :8080
    wind.WithServer(grpcServer),    // gRPC :9090
    wind.WithServer(wsServer),      // WebSocket :8081
)
// All three protocols start concurrently and share the same App lifecycle;
// any crash cascades into a full graceful exit

Related Documentation

  • Core Framework Introduction
  • Transport Protocol Plugins
  • Declarative Middleware Orchestration
  • Multi-Protocol Listening Tutorial
Edit this page
Last Updated:: 11/3/26, 2:14 PM
Contributors: Bobo
Prev
Context Propagation
Next
Log Facade Interface