GoWindGoWind
首页
框架
GoWind Toolkit
  • 开源项目

    • GoWind Admin(后台管理)
    • GoWind CMS(内容管理)
    • GoWind UBA(行为分析)
    • GoWind Shop(电商)
    • GoWind Kanban(协作看板)
    • GoWind Ledger(家庭记账)
    • GoWind ShortPlay(短剧社区)
    • GoWind Ops(运维平台)
    • RushWind(Rust 生态)
  • Open Core(社区开源 · 企业版增强)

    • GoWind OA(协同办公)
    • GoWind ERP(业财一体)
    • GoWind WMS(多货主仓储)
  • 商业产品

    • GoWind IM(即时通讯)
    • GoWind CRM(B2B 销售管理)
    • GoWind Trade(外贸全流程管理)
    • GoWind IoT(物联网)
    • GoWind Edu(AI 教育)
    • GoWind MES(制造执行)
    • GoWind CDC(数据管道)
    • GoWind SDP(零信任网关)
    • GoWind Quant(量化研究)
    • GoWind Trade Radar(外贸选品雷达)
    • GoWind Game Radar(游戏立项雷达)
  • 简体中文
  • English
GitHub
首页
框架
GoWind Toolkit
  • 开源项目

    • GoWind Admin(后台管理)
    • GoWind CMS(内容管理)
    • GoWind UBA(行为分析)
    • GoWind Shop(电商)
    • GoWind Kanban(协作看板)
    • GoWind Ledger(家庭记账)
    • GoWind ShortPlay(短剧社区)
    • GoWind Ops(运维平台)
    • RushWind(Rust 生态)
  • Open Core(社区开源 · 企业版增强)

    • GoWind OA(协同办公)
    • GoWind ERP(业财一体)
    • GoWind WMS(多货主仓储)
  • 商业产品

    • GoWind IM(即时通讯)
    • GoWind CRM(B2B 销售管理)
    • GoWind Trade(外贸全流程管理)
    • GoWind IoT(物联网)
    • GoWind Edu(AI 教育)
    • GoWind MES(制造执行)
    • GoWind CDC(数据管道)
    • GoWind SDP(零信任网关)
    • GoWind Quant(量化研究)
    • GoWind Trade Radar(外贸选品雷达)
    • GoWind Game Radar(游戏立项雷达)
  • 简体中文
  • English
GitHub
  • 介绍

    • GoWind 框架
    • 框架整体架构
  • go-wind 核心

    • go-wind 核心框架
    • App 生命周期管理
    • Context 传播
    • Transport 抽象
    • Log 门面接口
  • go-wind-plugins 插件

    • go-wind-plugins 插件总览
    • 插件配置系统
    • 插件注册机制(SPI)
    • 日志适配插件
    • 传输协议插件
    • 消息中间件插件
    • 编码解码插件
    • 安全与认证插件
    • 链路追踪插件
    • 缓存插件
    • 对象存储插件(OSS)
    • 限流插件
    • 指标监控插件
    • AI 插件
    • 工作流插件
    • 数据库与缓存插件
    • Bootstrap 集成与网关插件
    • 压缩与序列化插件
    • 模板渲染与验证插件
  • go-wind-bootstrap 启动器

    • go-wind-bootstrap 声明式启动器
    • Bootstrap 配置系统
    • Bootstrap SPI 机制
    • 声明式中间件编排
    • Bootstrap 命令行集成
    • Bootstrap 实战示例
  • go-wind-flow 流程引擎

    • GoWind Flow 流程引擎
  • 教程

    • 快速入门教程
    • 自定义插件开发教程
    • 多协议同时监听教程
    • 框架迁移指南

传输协议插件

go-wind-plugins 提供多种传输协议适配器,实现 transport.Server 接口。支持 HTTP、gRPC、WebSocket、SSE 等主流协议,并覆盖定时任务、异步任务队列、消息中间件订阅与 MCP 等 31 个传输插件。

一、协议总览

transport/ 下共 31 个插件目录,按形态分为四组:

协议与通信

插件导入路径引擎/说明典型场景
HTTPplugins/transport/httpnet/http,另含 chi / gin / fiber 三种驱动REST API
HTTP/3plugins/transport/http3quic-go/http3QUIC 低延迟 Web
gRPCplugins/transport/grpcgoogle.golang.org/grpc(server/client/middleware)内部服务调用
WebSocketplugins/transport/websocketgorilla/websocket实时通信
Socket.IOplugins/transport/socketiogoogollee/go-socket.io实时通信(Socket.IO 协议)
SignalRplugins/transport/signalrSignalR 协议.NET 生态实时通信
SSEplugins/transport/sseServer-Sent Events服务端事件推送
TCPplugins/transport/tcpnet.Listener自定义协议长连接
KCPplugins/transport/kcpxtaci/kcp-go低延迟游戏
WebRTCplugins/transport/webrtcpion/webrtc v4(SFU)音视频实时传输
WebTransportplugins/transport/webtransportwebtransport-goHTTP/3 上的双向流

RPC 与查询

插件导入路径引擎/说明
GraphQLplugins/transport/graphqlgraphql-go
Thriftplugins/transport/thriftApache Thrift
tRPCplugins/transport/trpctRPC 协议

定时与异步任务

插件导入路径引擎/说明
Cronplugins/transport/cronrobfig/cron 定时任务
HPTimerplugins/transport/hptimer高精度定时器
Asynqplugins/transport/asynqhibiken/asynq 异步任务队列
Machineryplugins/transport/machinerymachinery(类 Celery)分布式任务队列

消息中间件订阅型传输

插件导入路径中间件
Kafkaplugins/transport/kafkaApache Kafka
RabbitMQplugins/transport/rabbitmqRabbitMQ
NATSplugins/transport/natsNATS
MQTTplugins/transport/mqttMQTT
Pulsarplugins/transport/pulsarApache Pulsar
RocketMQplugins/transport/rocketmqApache RocketMQ
NSQplugins/transport/nsqNSQ
SQSplugins/transport/sqsAWS SQS
Redisplugins/transport/redisRedis Pub/Sub
ActiveMQplugins/transport/activemqApache ActiveMQ
Azure Service Busplugins/transport/azuresbAzure Service Bus
Google Pub/Subplugins/transport/gcpubsubGoogle Cloud Pub/Sub

AI 协议

插件导入路径引擎/说明
MCPplugins/transport/mcpModel Context Protocol(StreamableHTTP / SSE 两种服务形态)

二、HTTP Server

import httpPlugin "github.com/tx7do/go-wind-plugins/transport/http"

server := httpPlugin.NewServer(
    httpPlugin.WithAddr(":8080"),
    httpPlugin.WithHandler(router),
    httpPlugin.WithReadTimeout(10*time.Second),
    httpPlugin.WithWriteTimeout(10*time.Second),
    httpPlugin.WithTLS("cert.pem", "key.pem"),
    httpPlugin.WithCORS(true, []string{"*"}),
)

YAML 配置

server:
  http:
    addr: ":8080"
    read_timeout: 10s
    write_timeout: 10s
    idle_timeout: 60s
    max_header_bytes: 1048576
    cors:
      enabled: true
      origins: ["https://app.example.com"]
      methods: ["GET", "POST", "PUT", "DELETE"]
      credentials: true
    tls:
      enabled: true
      cert_file: certs/cert.pem
      key_file: certs/key.pem

三、gRPC Server

import grpcPlugin "github.com/tx7do/go-wind-plugins/transport/grpc"

server := grpcPlugin.NewServer(
    grpcPlugin.WithAddr(":9090"),
    grpcPlugin.WithServiceDesc(&pb.File_ServiceDesc),
    grpcPlugin.WithInterceptor(unaryInterceptor, streamInterceptor),
    grpcPlugin.WithTLS("cert.pem", "key.pem"),
    grpcPlugin.WithReflection(true),     // gRPC reflection
    grpcPlugin.WithHealthCheck(true),    // health check service
)

YAML 配置

server:
  grpc:
    addr: ":9090"
    max_recv_msg_size: 4194304
    max_send_msg_size: 4194304
    reflection: true
    health_check: true
    tls:
      enabled: false

注册 gRPC 服务

server := grpcPlugin.NewServer(
    grpcPlugin.WithAddr(":9090"),
    grpcPlugin.WithService(
        func(s *grpc.Server) {
            pb.RegisterUserServiceServer(s, &userService{})
        },
    ),
)

四、WebSocket Server

import wsPlugin "github.com/tx7do/go-wind-plugins/transport/websocket"

server := wsPlugin.NewServer(
    wsPlugin.WithAddr(":8081"),
    wsPlugin.WithPath("/ws"),
    wsPlugin.WithUpgrader(upgrader),
    wsPlugin.WithHandler(wsHandler),
    wsPlugin.WithReadBufferSize(4096),
    wsPlugin.WithWriteBufferSize(4096),
    wsPlugin.WithCheckOrigin(true),
)

WebSocket Handler

func wsHandler(conn *wsPlugin.Conn) {
    defer conn.Close()

    for {
        msgType, msg, err := conn.ReadMessage()
        if err != nil {
            break
        }
        // 广播消息
        conn.WriteMessage(msgType, msg)
    }
}

五、SSE Server

import ssePlugin "github.com/tx7do/go-wind-plugins/transport/sse"

server := ssePlugin.NewServer(
    ssePlugin.WithAddr(":8082"),
    ssePlugin.WithPath("/events"),
    ssePlugin.WithBufferSize(100),
)

推送事件

// 向特定客户端推送
server.Push(clientID, &ssePlugin.Event{
    Event: "notification",
    Data:  `{"message":"hello"}`,
})

// 广播
server.Broadcast(&ssePlugin.Event{
    Event: "update",
    Data:  `{"version":"v2.0"}`,
})

六、TCP Server

import tcpPlugin "github.com/tx7do/go-wind-plugins/transport/tcp"

server := tcpPlugin.NewServer(
    tcpPlugin.WithAddr(":9000"),
    tcpPlugin.WithHandler(tcpHandler),
    tcpPlugin.WithReadTimeout(30*time.Second),
    tcpPlugin.WithKeepAlive(true),
)

七、KCP Server

import kcpPlugin "github.com/tx7do/go-wind-plugins/transport/kcp"

server := kcpPlugin.NewServer(
    kcpPlugin.WithAddr(":9001"),
    kcpPlugin.WithHandler(kcpHandler),
    kcpPlugin.WithMTU(1400),
    kcpPlugin.WithNoDelay(1, 20, 2, 1),
)

八、GraphQL Server

import gqlPlugin "github.com/tx7do/go-wind-plugins/transport/graphql"

server := gqlPlugin.NewServer(
    gqlPlugin.WithAddr(":8083"),
    gqlPlugin.WithSchema(schema),
    gqlPlugin.WithPlayground(true),
    gqlPlugin.WithIntrospection(true),
)

九、多协议同时监听

app := wind.New(
    wind.WithName("multi-protocol"),
    wind.WithServer(httpServer),    // HTTP :8080
    wind.WithServer(grpcServer),    // gRPC :9090
    wind.WithServer(wsServer),      // WebSocket :8081
    wind.WithServer(sseServer),     // SSE :8082
)
app.Run(ctx)
server:
  http:
    addr: ":8080"
  grpc:
    addr: ":9090"
  websocket:
    addr: ":8081"
    path: /ws
  sse:
    addr: ":8082"
    path: /events

十、Endpoint 暴露

每个 Server 通过 Endpoint() 方法暴露访问地址,可用于服务注册:

for _, srv := range app.Servers() {
    for _, ep := range srv.Endpoint() {
        fmt.Printf("%s: %s\n", srv.Type(), ep)
    }
}
// 输出:
// http: http://0.0.0.0:8080
// grpc: grpc://0.0.0.0:9090
// websocket: ws://0.0.0.0:8081/ws

近期更新

  • MCP(transport/mcp):新增 WithMCPHTTPServerOptions / WithMCPSSEServerOptions,可透传 StreamableHTTP / SSE 服务选项(如 WithHTTPContextFunc),服务形态支持 ServerTypeHTTP 与 ServerTypeSSE 两种。

相关文档

  • Transport 抽象
  • 插件配置系统
  • 声明式中间件编排
  • 多协议同时监听教程
Edit this page
最近更新:: 2026/11/3 12:42
Contributors: Bobo
Prev
日志适配插件
Next
消息中间件插件