欢迎来到 艾瑞可erik 的魔法世界 🧙‍♂️

一只全栈开发的程序猿,偶尔做做运维、PHP、Goland、Python、Java、摄影、画画、写作、顺便睡觉,反正整站都搞过。

📚 289 篇文章 🏷️ 501 个标签 📂 89 个分类

🔥 最新文章

Ecat是Rust 微服务框架

Ecat

English | 简体中文

e-cat 是对标 go-kratos/kratos v3 的 Rust 微服务框架。

提供 API-first 开发体验、可插拔的组件架构、统一的 HTTP/gRPC 中间件抽象,以及完备的 CLI 工具链。让熟悉 Kratos 的开发者可以无缝上手,同时充分利用 Rust 的类型安全、零成本抽象和极致性能。

设计架构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
┌──────────────────────────────────────────────────────────────┐
│ ecat-cli │
│ (new │ proto │ run │ build) │
├──────────────────────────────────────────────────────────────┤
│ ecat (应用生命周期) │
│ AppBuilder → App { name, servers, hooks, ... } │
├────────────────────┬────────────────────┬────────────────────┤
│ transport │ middleware │ registry │
│ ───────── │ ────────── │ ──────── │
│ HTTP (axum) │ RecoveryLayer │ memory │
│ gRPC (tonic) │ TracingLayer │ │
│ encoding │ LoggingLayer │ │
│ │ TimeoutLayer │ │
│ │ SecurityLayer │ │
├────────────────────┼────────────────────┼────────────────────┤
│ config │ errors │ metadata │
│ ────── │ ────── │ ──────── │
│ file / env │ ErrorCode │ key-value │
│ remote source │ Error │ HTTP/gRPC │
├────────────────────┴────────────────────┴────────────────────┤
│ data 层 │
│ ──────────────────────────────────────────────── │
│ rdbms: SQLite / PostgreSQL / MySQL / TiDB │
│ cache: Redis / Memcached │
│ olap: ClickHouse │
│ search: OpenSearch / Elasticsearch │
│ graph: Neo4j / NebulaGraph / ArangoDB │
│ tsdb: InfluxDB / Apache IoTDB / QuestDB │
├──────────────────────────────────────────────────────────────┤
│ ecat-protos │
│ (共享 .proto 定义: errors, metadata, ...) │
└──────────────────────────────────────────────────────────────┘

请求处理流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
客户端请求

├─ HTTP :8000 ────→ axum::Router ──┐
│ │
└─ gRPC :9000 ────→ tonic::Server ─┤

┌───────┴───────┐
│ Middleware │
│ ────────── │
│ 1. Recovery │ 捕获 panic
│ 2. Tracing │ 注入 trace_id
│ 3. Logging │ 请求日志
│ 4. Auth │ 认证鉴权
│ 5. Metrics │ 指标采集
│ 6. Security │ 攻击检测(仅告警)
└───────┬───────┘

┌───────┴───────┐
│ Handler │ 用户业务逻辑
│ (tower::Service)│
└───────┬───────┘

┌───────┴───────┐
│ Response │ 编码序列化
│ JSON/Protobuf │
└───────────────┘

功能

  • API-first:Protobuf 定义 API、错误码、元数据;prost + tonic-build 代码生成
  • 双协议支持:HTTP(axum)和 gRPC(tonic)共用同一套 tower::Layer 中间件
  • 可插拔架构:Registry、Config、Logging、Encoding 全部通过 trait 抽象,默认提供生产可用实现
  • 中间件体系:内置 Recovery、Tracing、Logging、Timeout、Security;通过 tower::ServiceBuilder 组合
  • 应用生命周期:Builder 模式构建 App,多 Server 并发启动,SIGTERM/SIGINT 信号处理,start/stop 生命周期钩子
  • 类型安全:基于 protobuf 的错误码体系,编译期 HTTP 状态码映射
  • 可观测性:tracing + opentelemetry + Prometheus 开箱即用
  • 攻击检测:27 种攻击模式自动识别(SQL 注入、XSS、SSRF、路径遍历等),仅日志告警不阻断
  • 多数据源:RDBMS(SQLite/PG/MySQL/TiDB)、缓存、OLAP、搜索引擎、图数据库、时序数据库

Kratos 概念映射

Kratos (Go) e-cat (Rust) 说明
kratos.New() App::builder() Builder 模式
http.Handler tower::Service Rust 生态标准 trait
http.Server axum::Router 社区主流 HTTP 框架
grpc.Server tonic::transport::Server 最成熟的 gRPC 实现
proto generate prost + tonic-build 社区标准 protobuf
registry.Discovery Registry trait 可插拔注册发现
config.Source ConfigSource trait 多源配置加载

技术栈

组件 选型
异步运行时 tokio
HTTP axum
gRPC tonic
Protobuf prost + tonic-build
中间件 tower::Service / Layer
日志/追踪 tracing + opentelemetry-rust
指标 prometheus
序列化 serde + prost
攻击检测 security-rust
RDBMS sqlx
CLI clap

支持的数据库

类别 数据库 Crate Rust 驱动
RDBMS SQLite ecat-data-sqlx sqlx
RDBMS PostgreSQL ecat-data-sqlx sqlx
RDBMS MySQL ecat-data-sqlx sqlx
RDBMS TiDB ecat-data-sqlx sqlx
缓存 Redis ecat-data-redis redis-rs
缓存 Memcached ecat-data-memcached memcache
OLAP ClickHouse ecat-data-clickhouse clickhouse-rs
搜索 OpenSearch ecat-data-opensearch opensearch
搜索 Elasticsearch ecat-data-elasticsearch elasticsearch
Neo4j ecat-data-neo4j neo4rs
NebulaGraph ecat-data-nebulagraph nebula-client
ArangoDB ecat-data-arangodb arangors
时序 InfluxDB ecat-data-influxdb influxdb2
时序 Apache IoTDB ecat-data-iotdb iotdb-client-rs
时序 QuestDB ecat-data-questdb questdb-rs (ILP)

所有数据后端通过统一的 trait 抽象(RdbmsClient / Cache / SearchClient / GraphClient / TsdbClient),按需引入对应 contrib crate。

项目结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
e-cat/
├── ecat/ # 核心:App 生命周期
├── ecat-transport/ # 传输抽象(Server trait)
├── ecat-transport-http/ # axum 实现
├── ecat-transport-grpc/ # tonic 实现
├── ecat-middleware/ # tower::Layer 中间件
├── ecat-protos/ # Protobuf 定义
├── ecat-errors/ # 错误码体系
├── ecat-metadata/ # 元数据传递
├── ecat-encoding/ # 序列化抽象
├── ecat-logging/ # tracing 集成
├── ecat-registry/ # 服务注册发现
├── ecat-config/ # 配置管理
├── ecat-metrics/ # Prometheus 集成
├── ecat-data/ # 数据访问 trait
├── ecat-security/ # 攻击检测(security-rust)
├── ecat-cli/ # CLI 工具
├── docs/ # 设计文档与实现计划
└── examples/ # 示例项目

快速开始

前提条件

  • Rust 1.80+(stable 工具链)
  • protoc(Protocol Buffers 编译器)

安装 CLI

1
cargo install ecat-cli

创建服务

1
2
3
4
5
6
7
8
9
10
11
12
13
# 脚手架生成项目
ecat new helloworld
cd helloworld

# 添加 proto 定义
ecat proto add api/helloworld/helloworld.proto

# 生成客户端和服务端代码
ecat proto client api/helloworld/helloworld.proto
ecat proto server api/helloworld/helloworld.proto -t internal/service

# 开发模式运行
ecat run

访问 http://localhost:8000/helloworld/ecat

代码示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use ecat::App;
use ecat_transport_http::HttpServer;
use ecat_transport_grpc::GrpcServer;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let http_srv = HttpServer::new(":8000");
let grpc_srv = GrpcServer::new(":9000");

let app = App::builder()
.name("my-service")
.version("v1.0.0")
.server(http_srv)
.server(grpc_srv)
.on_start(|| async {
tracing::info!("service started");
Ok(())
})
.on_stop(|| async {
tracing::info!("service stopped");
Ok(())
})
.build()?;

app.run().await?; // 阻塞直到 SIGTERM/SIGINT
Ok(())
}

中间件

1
2
3
4
5
6
7
8
9
10
use tower::ServiceBuilder;
use ecat_middleware::{RecoveryLayer, TracingLayer, LoggingLayer, TimeoutLayer};
use std::time::Duration;

let layer = ServiceBuilder::new()
.layer(RecoveryLayer)
.layer(TracingLayer)
.layer(LoggingLayer)
.layer(TimeoutLayer::new(Duration::from_secs(30)))
.layer(SecurityLayer::new());

错误处理

1
2
3
4
5
6
7
8
9
10
11
12
use ecat_errors::{Error, ErrorCode};

fn get_user(id: u64) -> Result<User, Error> {
if id == 0 {
return Err(Error::new(
ErrorCode::InvalidArgument,
"bad_request",
"user id must be positive",
));
}
// ...
}

实现阶段

阶段 状态 内容
Phase 1 ✅ 完成 项目骨架、protos、errors、metadata、encoding、logging
Phase 2 ✅ 完成 Transport 层(HTTP + gRPC)
Phase 3 ✅ 完成 Middleware 体系(Recovery/Tracing/Logging/Timeout)
Phase 4 ✅ 完成 App 生命周期管理
Phase 5 ✅ 完成 Registry、Config、Metrics
Phase 5.5 ✅ 完成 Data 访问层(traits + sqlx 后端)
Phase 6 ✅ 完成 CLI 工具链(new/proto/run/build)
Phase 7 ✅ 完成 README、示例(helloworld)、设计文档
Phase 8 ✅ 完成 攻击检测集成(security-rust, ecat-security)

设计目标

# 目标 说明
1 Kratos 对齐 保持 Kratos 的 API-first、可插拔、统一抽象理念
2 Rust 惯用 复用 tower::Service、trait 泛型、零成本抽象;不做「Go in Rust」
3 类型安全 编译期捕获错误,Protobuf 定义全强类型化
4 可插拔 Registry、Config、Logging、Encoding 全部通过 trait 抽象
5 工具链完备 CLI 支持项目脚手架、proto 代码生成、开发运行
6 性能优先 零成本抽象 + 异步运行时
7 可观测 tracing + OpenTelemetry + Prometheus 开箱即用

技术说明

为什么选择 tower::Service

tower::Service 是 Rust 异步生态的 http.Handler 等价物。axum 和 tonic 都构建在 tower 之上,因此 e-cat 不需要自定义中间件 trait——直接提供 tower::Layer 实现即可达到与 Kratos 中间件相同的效果,且零适配器开销。

为什么用 Cargo Workspace

与 Kratos 的模块化设计一致。每个 ecat-* crate 独立版本、独立编译,用户按需引入。核心 crate 保持最小依赖,contrib crate 提供可选集成。

为什么用 prost(而非 protobuf-rs)

prost 是 Rust 社区最广泛使用的 protobuf 实现,编译期生成类型安全代码,与 tonic 深度集成。

设计文档

许可证

MIT

Coding to Rust 是一个 Claude Code 技能集合,覆盖从 16 种主流编程语言迁移到 Rust 的完整skills

Coding to Rust — 多语言迁移到 Rust 的技能集合

English

项目介绍

Coding to Rust 是一个 Claude Code 技能集合,覆盖从 16 种主流编程语言迁移到 Rust 的完整指南。每种语言提供:

  • 架构映射 — 运行时差异、范式转换、内存模型对照
  • 类型系统对照表 — 30-80 条精确的类型/语法映射
  • 框架迁移指南 — 主流框架到 Rust 生态的对照(如 Django→Axum、Spring→Actix)
  • 标准模式对照 — 带代码示例的 before/after 对比
  • 常见错误 — 该语言开发者在 Rust 中最容易犯的错误及修复方法
  • FFI 渐进迁移策略 — 分阶段替换方案
  • 参考实现 — 真实世界的迁移案例和项目

Security rust攻击检测库

Security rust

English | 中文

Rust 编写的攻击检测库,覆盖注入攻击、协议攻击、数据/序列化攻击、文件/敏感数据泄露 4 大类共 27 个检测器。零外部框架依赖,纯字符串扫描。


设计思路

为什么用「检测」而非「拦截」

本库定位为纯输入扫描器——接收字符串,返回结构化检测结果。不绑定任何 Web 框架,不做 HTTP 请求/响应解析,不实现实时阻断。这样你可以把它嵌入到任何链路中:WAF 规则引擎、日志审计、API 网关前置校验、CLI 安全扫描工具等。

Security Go — 攻击检测库

Security Go — 攻击检测库

English

Go 语言编写的攻击检测包,覆盖 32 个检测器5 大攻击类别3 种可插拔存储后端。统一接口 + 注册表模式,纯检测库,适配任何 Go HTTP 框架。

设计思路

核心原则

  • 零依赖检测 — 所有检测器仅使用 Go 标准库 regexp,无外部依赖
  • 统一接口 — 每个检测器实现 Detector 接口(Name() + Detect()),通过 Engine 注册表统一管理
  • 预编译正则 — 所有模式在 var 初始化时编译,运行时零开销
  • 按需配置 — 注入/协议/数据/文件检测器即插即用;HTTP 校验器需应用自定义配置

工业网络通信协议集 —— 微内核 + 协议 SDK 架构,覆盖 40 种工业协议,兼容 6 种 PHP 运行时环境

PHP 工业网络通信协议集 —— 微内核 + 协议 SDK 架构,覆盖 40 种工业协议,兼容 6 种 PHP 运行时环境。

English

目录


项目简介

Industrial Protocols 是一个面向 PHP 生态的工业通信协议集,采用 微内核 + 协议 SDK 架构。40 个协议包(15 个纯 PHP 实现 + 25 个 Bridge 桥接),每个包都是独立 GitHub 仓库和 Composer 包,通过 Packagist 按需安装。

核心理念: 内核只定义「协议是什么」,不包含任何具体协议实现。用户按需安装协议包,内核启动时通过 composer.jsonextra 字段自动发现并注册。

1
composer require erikwang2013/industrial-protocols-kernel erikwang2013/industrial-protocols-modbus

Global Game Platform全球游戏聚合平台

全球游戏聚合平台 (Global Game Platform)

Copyright (c) 2026 erik erik@erik.xyzhttps://erik.xyz

全球通用、国际化的游戏聚合平台。用户注册后在平台充值兑换游戏币,用游戏币玩游戏、赚取游戏币,游戏币可转回钱包提现。后台提供完整的游戏管理、提现审核、用户管理和支付管理功能。支持多语言切换(英文/中文)。

版本策略

版本 目标 状态
基础版 (MVP) 跑通核心闭环:注册→充值→兑换→游戏→提现→审核 已完成
标准版 生产可用:全球化支付、第三方游戏SDK、基础风控、三端前端 规划中
完整版 完全体:多语言、排行榜、优惠券、完整风控、全量功能 规划中

Property Management Platform物业管理系统

物业管理系统 (Property Management Platform)

Copyright (c) 2026 erik erik@erik.xyzhttps://erik.xyz

全栈物业管理系统,覆盖小区管理、费用收缴、报修维护、停车门禁、安保保洁等15个业务模块。管理员端(admin)和业主端(service)分离部署,前端覆盖 Flutter Web(PC 管理后台风格)与 HarmonyOS 移动端。

项目结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
property-management-platform/
├── admin/ # 管理员端 webman v2 项目
│ ├── app/
│ │ ├── admin/controller/ # 管理端控制器
│ │ ├── api/v1/controller/ # 公开 API 控制器
│ │ ├── common/ # 公共工具类
│ │ ├── middleware/ # 中间件(认证/鉴权/限流/安全)
│ │ ├── model/ # 数据模型(Eloquent ORM)
│ │ ├── queue/ # 队列任务
│ │ └── process/ # 进程管理
│ ├── apps/
│ │ ├── flutter/ # 管理后台 Flutter Web(PC 风格)
│ │ └── harmonyos/ # 管理后台 HarmonyOS App
│ ├── config/ # 配置文件(含中文注释)
│ ├── database/
│ │ ├── migrations/ # SQL 迁移文件
│ │ └── backup/ # 数据库备份脚本
│ ├── resource/
│ │ └── translations/ # 国际化语言文件(zh_CN / en)
│ ├── docs/ # 管理端文档
│ ├── tests/ # 单元测试
│ └── public/ # Web 入口
├── service/ # 业主业务端 webman v2 项目
│ ├── app/
│ │ ├── api/v1/controller/ # 业主端 API 控制器
│ │ ├── common/ # 公共工具类
│ │ ├── middleware/ # 中间件
│ │ ├── model/ # 数据模型
│ │ └── process/ # 进程管理
│ ├── config/ # 配置文件
│ ├── resource/
│ │ └── translations/ # 国际化语言文件
│ └── database/migrations/ # SQL 迁移文件
├── apps/
│ ├── flutter/ # 业主端 Flutter Web(PC 风格)
│ └── harmonyos/ # 业主端 HarmonyOS App
└── docs/ # 项目文档
├── ARCHITECTURE.md
├── ARCHITECTURE_DESIGN.md
├── API.md
├── FEATURES.md
└── FEATURE_DESIGN.md

Open Erp 开放ERP系统

开放ERP系统 (open-erp)

基于 webman v2 + Flutter 的全栈ERP系统。

功能清单

业务域 功能 说明
🔐 认证 登录/注册/刷新令牌/登出 点击验证码 + JWT + 黑名单
账号锁定 5 次失败锁定 15 分钟
并发会话限制 同一用户最多 3 个有效 Token
📊 仪表盘 经营总览/销售看板/库存看板/财务看板 Redis 缓存 5 分钟
👥 用户管理 CRUD + 批量删除/启禁用 软删除 + 密码二次确认
Excel 批量导入 逐行校验 + 错误报告
🔒 角色权限 角色 CRUD + 权限树 RBAC method.path 粒度鉴权
⚙ 系统配置 键值对 CRUD 分组管理
📋 操作审计 日志查询 + 来源端检测 8 平台自动识别
📁 文件管理 上传/Excel 导出/PDF 导出 敏感数据自动脱敏
🛡 安全防护 18 层纵深防御 XSS/SQL注入/路径遍历/命令注入/CSRF/限流/CSP…
🏥 运维 健康检查/metrics/API 文档/security.txt Prometheus + OpenAPI 3.0
📦 商品管理 商品档案/SKU/多规格/多单位/分类/品牌/价格策略 多级分类树 + 多单位换算
仓库库位 多仓库多库位管理
供应商/客户档案 联系人/银行账户/信用额度
📥 采购管理 申请→订单→收货→退货→结算 完整采购流程 + 审批
📤 销售管理 报价→订单→发货→退货→结算 报价转订单 + 销售毛利
🏗 库存管理 实时库存/批次/序列号/调拨/盘点/预警 移动加权平均成本核算
💰 财务管理 应收应付/收付款/日记账/报销/利润表/固定资产/税务/多币种/预算/成本利润中心 自动生成应收应付 + 核销 + 全面财务管理
🤝 CRM 客户/联系人/跟进记录/营销活动/服务工单/分析报表/销售漏斗/公海池/报价/合同 客户全生命周期管理
✅ 审批工作流 工作流定义/提交审批/批准/拒绝/撤回/我的审批 多节点审批流程引擎
🔔 消息通知 通知列表/已读标记/未读计数/全部已读 实时消息推送与状态追踪
📐 项目管理 项目/任务/工时记录 项目进度跟踪与资源管理
👤 人力资源 部门/员工/职位/考勤/请假/薪资 全面人事管理
🏭 生产制造 BOM/生产订单/工艺路线/工作站/MRP 物料需求计划与生产执行
📈 自定义报表 报表模板/数据集/字段/筛选器/执行/定时调度 可视化报表构建器

Erik Shop 跨境电商平台

Erik Shop — 跨境电商平台

基于 webman 全家桶构建的全栈跨境电商平台,覆盖 B2C/B2B 场景和第三方卖家入驻。

Erik Shop — 三版本对比

Copyright (c) 2026 erik erik@erik.xyzhttps://erik.xyz


版本概览

简化版 (Lite) 标准版 (Standard) 完整版 (Full)
定位 个人开发者 / 小型电商 成长型跨境商家 企业级全栈平台
许可证 MIT 开源 商业授权 商业授权
获取方式 GitHub 公开下载 联系 erik@erik.xyz 联系 erik@erik.xyz
分支 lite standard full
当前

Ads Platform多平台广告管理系统

Ads Platform — 多平台广告管理系统

统一管理广告投放与跨平台数据报表,支持告警监控、自动出价、多端访问

版本对比

Copyright (c) 2026 erik erik@erik.xyzhttps://erik.xyz

版本 授权 获取方式
简化版 (Lite) 开源 (MIT) GitHub 公开仓库
标准版 (Standard) 商业授权 联系 erik@erik.xyz
完整版 (Full) 商业授权 联系 erik@erik.xyz