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 的数据访问层(crud/)以泛型 Repository / Client 为核心(家族内部接口,非 go-wind 框架接口),提供 19 个模块:9 个数据库引擎、4 个向量/图数据库引擎、1 个统一向量契约(vector),以及 5 个家族共享设施(api / pagination / cache / audit / viewer)。

一、数据访问引擎(CRUD)

1.1 支持的数据库

数据库导入路径说明
GORMplugins/crud/gormGORM 关系型 ORM(MySQL、PostgreSQL、SQLite、SQL Server、ClickHouse 等)
Entplugins/crud/entgoEnt 关系型 ORM(代码生成)
MongoDBplugins/crud/mongodbMongoDB 文档数据库
ClickHouseplugins/crud/clickhouseClickHouse 列式 OLAP
Apache Dorisplugins/crud/dorisApache Doris 分析型数据库(MySQL 协议)
Elasticsearchplugins/crud/elasticsearchElasticsearch 全文检索
OpenSearchplugins/crud/opensearchOpenSearch 全文检索
InfluxDBplugins/crud/influxdbInfluxDB 时序数据库
Cassandraplugins/crud/cassandraCassandra 宽列存储(开发中,尚未可用)

1.2 使用示例(GORM)

import (
    "github.com/tx7do/go-utils/mapper"
    "github.com/tx7do/go-wind-plugins/crud/gorm"
)

// 创建 Mapper(DTO <-> Entity)
m := mapper.NewCopierMapper[User, UserEntity]()

// 创建 Repository
repo := gorm.NewRepository[User, UserEntity](m,
    gorm.WithDriverName("mysql"),
    gorm.WithDSN("user:pass@tcp(localhost:3306)/mydb?parseTime=true"),
    gorm.WithReplicaDsns([]string{ /* 只读副本 DSN */ }),
    gorm.WithEnableTrace(true),
    gorm.WithEnableMigrate(true),
    gorm.WithAutoMigrate(&UserEntity{}),
)

Repository 提供完整 CRUD、Offset/Page/Token 三种分页、结构化过滤、多字段排序、FieldMask 字段选择,可选接入 Redis 缓存(防击穿)。

1.3 连接与迁移选项

常用 Option(以 GORM 为例):WithGormDB(注入已有 *gorm.DB)、WithDriverName、WithDSN、WithReplicaDsns(读写分离副本)、WithEnableTrace、WithEnableMetrics(Prometheus 指标)、WithEnableDbResolver、WithAutoMigrate、WithMixin(s)(字段审计等混入)。

二、向量与图数据库

2.1 引擎清单

引擎导入路径说明
Qdrantplugins/crud/qdrant纯向量数据库(官方 gRPC 客户端,点 = ID + 向量 + Payload)
Milvusplugins/crud/milvus纯向量数据库(行 = 主键 + 标量列 + 向量列)
Neo4jplugins/crud/neo4j图数据库(节点 = 行,属性 = 列的表式用法)
Weaviateplugins/crud/weaviate向量数据库(对象 = UUID + 属性 + 向量)

2.2 统一向量契约 vector

crud/vector 定义跨引擎统一的向量检索契约(RAG / 语义检索场景),不依赖任何数据库驱动,由各引擎模块把同一份 Query 映射到各自底层语法:

引擎底层语法
Elasticsearch 8+/9.x顶层 knn 子句 + dense_vector
OpenSearch 2.11+query.knn + knn_vector
GORM (PostgreSQL)pgvector <-> / <=> / <#>
MongoDB Atlas 7.0+$vectorSearch 聚合阶段
ClickHousecosineDistance / L2Distance / dotProduct
Apache Doris 3.0+cosine_distance / l2_distance / inner_product
import "github.com/tx7do/go-wind-plugins/crud/vector"

q := &vector.Query{
    Field:  "embedding",
    Vector: []float32{0.1, 0.2, 0.3},
    TopK:   10,
    Metric: vector.DistanceMetricCosine,
}

res, _ := repo.SearchByVector(ctx, q) // Hit.Score 恒为「越大越相似」

三、家族共享设施

模块导入路径说明
API 契约plugins/crud/apiProtobuf 分页/过滤/排序协议定义与 buf 生成代码
Paginationplugins/crud/pagination分页器(Offset/Page/Token)与过滤、排序格式转换
Cacheplugins/crud/cacheCache-Aside 缓存与 SingleFlight 防击穿
Auditplugins/crud/audit审计日志接口与 Context 注入
Viewerplugins/crud/viewer身份上下文与五级数据范围(行级权限)

四、服务注册发现

4.1 适配器列表

注册中心导入路径特点
Consulplugins/registry/consulHashiCorp、健康检查
Etcdplugins/registry/etcdKubernetes 基础、Raft 一致性
Eurekaplugins/registry/eurekaSpring Cloud 集成
Kubernetesplugins/registry/kubernetesK8s Endpoints
Nacosplugins/registry/nacos阿里系、配置+注册一体化
Polarisplugins/registry/polaris腾讯云 Polaris
ServiceCombplugins/registry/servicecombApache ServiceComb
ZooKeeperplugins/registry/zookeeper经典、强一致性

4.2 服务注册

import consulPlugin "github.com/tx7do/go-wind-plugins/registry/consul"

reg := consulPlugin.New(
    consulPlugin.WithAddr("localhost:8500"),
    consulPlugin.WithServiceName("my-service"),
    consulPlugin.WithServiceAddr("10.0.0.1"),
    consulPlugin.WithServicePort(8080),
    consulPlugin.WithHealthCheck("http://10.0.0.1:8080/health", 10*time.Second),
    consulPlugin.WithTags("v1", "primary"),
)

4.3 服务发现

// 获取服务实例列表
instances, _ := reg.GetService(ctx, "my-service")
for _, ins := range instances {
    fmt.Printf("%s:%d (weight=%d, healthy=%v)\n",
        ins.Address, ins.Port, ins.Weight, ins.Healthy)
}

// 负载均衡
lb := registry.NewRoundRobin(instances)
instance := lb.Select()

4.4 YAML 配置

registry:
  consul:
    addr: "localhost:8500"
    scheme: http
    health_check:
      interval: 10s
      timeout: 5s
      deregister_after: 60s
    tags: ["v1", "primary"]

五、配置中心

5.1 适配器列表

配置中心导入路径特点
Fileplugins/config/file本地 YAML/JSON
Etcdplugins/config/etcd分布式 KV
Consulplugins/config/consulConsul KV
Nacosplugins/config/nacos配置+注册
Apolloplugins/config/apollo携程开源

5.2 动态配置

import nacosConfigPlugin "github.com/tx7do/go-wind-plugins/config/nacos"

source := nacosConfigPlugin.New(
    nacosConfigPlugin.WithAddr("localhost:8848"),
    nacosConfigPlugin.WithNamespace("production"),
    nacosConfigPlugin.WithDataID("my-service.yaml"),
    nacosConfigPlugin.WithGroup("DEFAULT_GROUP"),
    nacosConfigPlugin.WithWatch(true),     // 监听配置变更
)

5.3 配置热更新

source.Watch(func(event config.Event) {
    fmt.Println("config changed:", event.Key)
    // 重新加载配置
    reloadConfig(event.Value)
})

六、多源配置合并

config:
  sources:
    - type: file
      path: ./config.yaml
    - type: nacos
      addr: localhost:8848
      data_id: my-service.yaml
  # 后加载的源覆盖先加载的

相关文档

  • 插件配置系统
  • 缓存插件
  • 插件总览
Edit this page
最近更新:: 2026/11/3 12:42
Contributors: Bobo
Prev
工作流插件
Next
Bootstrap 集成与网关插件