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 流程引擎
  • 教程

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

框架整体架构

本文档介绍 GoWind 框架三个项目的分层架构、模块关系和数据流。

一、三层架构

二、核心层(go-wind)

2.1 职责

模块文件职责
Appapp.go引擎核心:生命周期管理、优雅启停
Transporttransport/传输层抽象:Server 接口定义
Loglog/日志门面:Logger 接口 + Level + 全局注册
Contextcontext.go请求级元数据传播:TraceID / UserID / Metadata
Instanceinstance.go服务实例模型
Errorserrors.go统一错误定义

2.2 核心接口

// Transport Server 接口
type Server interface {
    Start(context.Context) error
    Stop(context.Context) error
    Endpoint() []string
}

// Log 门面接口
type Logger interface {
    Log(level Level, msg string, fields ...Field)
    With(fields ...Field) Logger
}

// App 引擎
type App struct {
    servers   []Server
    logger    Logger
    // ...
}

func (a *App) Run(ctx context.Context) error
func (a *App) Stop(ctx context.Context) error

2.3 生命周期

三、实现层(go-wind-plugins)

3.1 统一接口

每个领域的插件实现 go-wind 核心定义的接口:

// 配置中心接口
type Config interface {
    Load() (*Value, error)
    Watch() (<-chan *Value, error)
}

// 服务注册接口
type Registry interface {
    Register(ctx context.Context, svc *Service) error
    Deregister(ctx context.Context, svc *Service) error
    GetService(ctx context.Context, name string) ([]*Service, error)
}

// 消息队列接口
type Broker interface {
    Publish(ctx context.Context, topic string, msg *Message) error
    Subscribe(ctx context.Context, topic string, handler Handler) (Subscriber, error)
}

3.2 插件目录结构

go-wind-plugins/
├── config/           # 配置中心
│   ├── apollo/
│   ├── consul/
│   ├── etcd/
│   ├── file/
│   ├── nacos/
│   └── ...
├── registry/         # 服务注册
│   ├── consul/
│   ├── etcd/
│   ├── nacos/
│   └── ...
├── log/              # 日志
│   ├── zap/
│   ├── zerolog/
│   ├── logrus/
│   └── ...
├── transport/        # 传输协议
│   ├── http/
│   ├── grpc/
│   ├── websocket/
│   └── ...
├── broker/           # 消息队列
│   ├── kafka/
│   ├── rabbitmq/
│   ├── nats/
│   └── ...
├── encoding/         # 编解码
├── security/         # 安全
├── cache/            # 缓存
├── oss/              # 对象存储
├── tracer/           # 链路追踪
├── metrics/          # 指标监控
├── ratelimit/        # 限流
├── circuitbreaker/   # 熔断
├── ai/               # AI 集成
├── workflow/         # 工作流
├── health/           # 健康检查
├── retry/            # 重试
└── go.work           # Go Workspace 多模块管理

3.3 独立版本管理

每个插件子目录拥有独立的 go.mod,可以独立引用和版本化:

// 只引入需要的插件
import (
    _ "github.com/tx7do/go-wind-plugins/transport/http"
    _ "github.com/tx7do/go-wind-plugins/log/zap"
    _ "github.com/tx7do/go-wind-plugins/registry/etcd"
)

四、装配层(go-wind-bootstrap)

4.1 配置驱动

# 一份 YAML 描述完整应用拓扑
name: order-service

servers:
  - name: http-api
    type: http
    addr: ":8080"
    middleware: [log, recovery, cors, auth]

  - name: grpc-api
    type: grpc
    addr: ":9090"

log:
  level: info
  format: json
  adapter: zap

config:
  type: nacos
  config:
    server: "nacos:8848"
    namespace: production

registry:
  type: etcd
  config:
    endpoints: ["etcd:2379"]

tracer:
  type: otlp
  config:
    endpoint: "jaeger:4317"

4.2 SPI 机制

// 插件通过 init() 自注册
package http

import "github.com/tx7do/go-wind-bootstrap"

func init() {
    bootstrap.RegisterServer("http", NewHTTPServer)
}

// 业务代码只需 blank import
import _ "github.com/tx7do/go-wind-plugins/transport/http"

4.3 Builder 解析链

五、数据流

5.1 请求处理流

5.2 服务发现流

六、技术选型矩阵

领域推荐选择备选
配置中心NacosApollo, Consul, Etcd
服务注册EtcdConsul, Nacos
日志ZapZerolog, Logrus
传输协议HTTP + gRPCWebSocket, SSE
消息队列KafkaRabbitMQ, NATS
链路追踪OTLP → Jaeger—
安全JWT + Casbin—
缓存RedisLocal Cache
对象存储MinIOS3
限流SentinelToken Bucket, BBR

相关文档

  • GoWind 框架介绍
  • 核心框架介绍
  • 插件生态总览
  • 声明式启动器介绍
Edit this page
最近更新:: 2026/6/21 21:28
Contributors: Bobo
Prev
GoWind 框架