GoWind 开源生态GoWind 开源生态
首页
框架
GoWind Admin
GoWind CMS
GoWind IM
GoWind UBA
GoWind IoT
GoWind Toolkit
GoWind Quant
GitHub
首页
框架
GoWind Admin
GoWind CMS
GoWind IM
GoWind UBA
GoWind IoT
GoWind Toolkit
GoWind Quant
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 CLI 工具
    • Bootstrap 实战示例
  • 教程

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

压缩与序列化插件

go-wind-plugins 提供压缩和序列化辅助插件,减少网络传输体积和存储空间。

一、压缩插件

1.1 适配器列表

适配器导入路径压缩率速度
Gzipplugins/compress/gzip高中
Snappyplugins/compress/snappy中极快
LZ4plugins/compress/lz4中极快
Zstdplugins/compress/zstd高快
Brotliplugins/compress/brotli最高慢

1.2 使用方式

import compressPlugin "github.com/tx7do/go-wind-plugins/compress/gzip"

compressor := compressPlugin.New(
    compressPlugin.WithLevel(6),        // 1-9
)

// 压缩
compressed, _ := compressor.Compress(data)

// 解压
original, _ := compressor.Decompress(compressed)

1.3 HTTP 响应压缩

// Transport 自动支持 Accept-Encoding: gzip
// 客户端发送 Accept-Encoding: gzip
// 服务端自动压缩响应体

1.4 Kafka 消息压缩

broker:
  kafka:
    producer:
      compression: zstd         # none | gzip | snappy | lz4 | zstd

二、序列化对比

格式体积速度可读性Schema
JSON大快是无
Protobuf最小最快否.proto
MessagePack小快否无
YAML中慢是无
TOML中慢是无
Avro小快否.avsc

三、Schema 演进

Protobuf(推荐)

// user.proto
syntax = "proto3";

message User {
    string id = 1;
    string name = 2;
    string email = 3;
    // 新增字段使用新编号,不破坏兼容性
    string phone = 4;
}

兼容性规则

操作兼容性
新增字段向前兼容
删除字段向后兼容(需保留字段号)
修改字段类型不兼容
修改字段编号不兼容

相关文档

  • 编码解码插件
  • 消息中间件插件
  • 插件总览
Edit this page
Last Updated:: 6/21/26, 9:28 PM
Contributors: Bobo
Prev
Bootstrap 集成与网关插件
Next
模板渲染与验证插件