genesis

module
v1.0.0-rc.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: MIT

README

Genesis

一个面向 Go 微服务的轻量组件库,而不是框架。

Genesis 将日志、配置、连接管理、缓存、分布式锁、消息、认证、限流、熔断和 服务发现等通用能力沉淀成可以按需组合的 Go 包。它不接管应用生命周期,也不要求 使用依赖注入容器。

最低支持 Go 1.26.0。当前预发行版本为 v1.0.0-rc.2, 发布提交为 f78d7860849019ae5a35c6473420b5e7db2269a0。 主线后续的可观测性与 JetStream 修复尚未发布;CI 通过不会自动产生新版本。

设计原则

  • 显式依赖注入,不使用运行时 DI 容器。
  • 组件按能力分层,代码目录保持扁平。
  • 谁创建资源,谁负责关闭。
  • 统一入口不等于抹平后端差异。

架构分层

层次 组件 说明
基础能力 clog、config、metrics、trace、xerrors 日志、配置、可观测性和错误处理
基础设施 connector、db 外部连接与数据库访问
业务能力 cache、idgen、dlock、idem、mq 可复用的业务基础能力
服务治理 auth、ratelimit、breaker、registry 认证、流量治理和服务发现

每个组件都可以独立导入:

import "github.com/ceyewan/genesis/cache"

具体配置和用法见各组件目录下的 README.md、GoDoc 与 example_test.go。

常用命令

make help
make check
make test-race
make examples

真实集成测试通过 internal/testkit 自动启动 Testcontainers,无需预先执行 make up。make up 只用于运行依赖外部服务的示例。

文档

License

MIT

Directories

Path Synopsis
Package auth 提供基于 JWT 的双令牌认证能力。
Package auth 提供基于 JWT 的双令牌认证能力。
Package breaker 提供了面向 gRPC 客户端场景的轻量熔断组件。
Package breaker 提供了面向 gRPC 客户端场景的轻量熔断组件。
Package cache 提供 Genesis L2 业务层的缓存组件族,支持分布式缓存、本地缓存和多级缓存。
Package cache 提供 Genesis L2 业务层的缓存组件族,支持分布式缓存、本地缓存和多级缓存。
serializer
Package serializer defines the value encoding boundary used by cache.
Package serializer defines the value encoding boundary used by cache.
Package clog 为 Genesis 提供统一的结构化日志接口。
Package clog 为 Genesis 提供统一的结构化日志接口。
Package config 为 Genesis 提供统一的多源配置加载与文件驱动的变更通知能力。
Package config 为 Genesis 提供统一的多源配置加载与文件驱动的变更通知能力。
Package connector 为 Genesis 提供统一的连接管理能力。
Package connector 为 Genesis 提供统一的连接管理能力。
Package db 提供基于 GORM 的数据库组件,是 Genesis L1 基础设施层的一部分。
Package db 提供基于 GORM 的数据库组件,是 Genesis L1 基础设施层的一部分。
Package dlock 提供 Genesis 的分布式锁组件。
Package dlock 提供 Genesis 的分布式锁组件。
examples
async-task command
auth command
breaker command
breaker/internal/proto/demo/v1
Package pb contains generated code used only by the breaker example.
Package pb contains generated code used only by the breaker example.
cache command
cached-query command
clog command
config command
connector command
examples/connector/main.go
examples/connector/main.go
db command
dlock command
grpc-governance command
grpc-registry command
grpc-registry/internal/proto
Package proto contains generated code used only by the grpc-registry example.
Package proto contains generated code used only by the grpc-registry example.
idem command
idem/internal/proto
Package pb contains generated code used only by the idempotency example.
Package pb contains generated code used only by the idempotency example.
idgen command
mq command
examples/mq/main.go
examples/mq/main.go
observability/internal/proto
Package proto contains generated code used only by the observability example.
Package proto contains generated code used only by the observability example.
ratelimit command
registry command
xerrors command
Package idem 提供结果复用型幂等组件,用于抑制同一请求或消息的重复成功提交。
Package idem 提供结果复用型幂等组件,用于抑制同一请求或消息的重复成功提交。
Package idgen 提供 Genesis L2 业务层的 ID 生成能力。
Package idgen 提供 Genesis L2 业务层的 ID 生成能力。
internal
cmd/apiinventory command
Command apiinventory generates the reviewed Genesis v1 exported API surface.
Command apiinventory generates the reviewed Genesis v1 exported API surface.
cmd/mdlinkcheck command
Command mdlinkcheck validates repository-local links in Markdown files.
Command mdlinkcheck validates repository-local links in Markdown files.
testkit
Package testkit 提供 Genesis 仓库内部组件测试所需的通用 helper。
Package testkit 提供 Genesis 仓库内部组件测试所需的通用 helper。
Package metrics 提供 Genesis 的 OpenTelemetry 指标封装与 Prometheus 暴露能力。
Package metrics 提供 Genesis 的 OpenTelemetry 指标封装与 Prometheus 暴露能力。
Package mq 提供消息队列组件,支持 NATS JetStream 和 Redis Stream 两种后端。
Package mq 提供消息队列组件,支持 NATS JetStream 和 Redis Stream 两种后端。
Package ratelimit 提供 Genesis 的限流组件。
Package ratelimit 提供 Genesis 的限流组件。
Package registry 提供了基于 Etcd 的服务注册发现组件,以及面向 gRPC 的 resolver 集成。
Package registry 提供了基于 Etcd 的服务注册发现组件,以及面向 gRPC 的 resolver 集成。
Package trace 提供 Genesis 的 OpenTelemetry 链路追踪初始化与传播辅助能力。
Package trace 提供 Genesis 的 OpenTelemetry 链路追踪初始化与传播辅助能力。
Package xerrors 提供 Genesis 的轻量错误封装工具。
Package xerrors 提供 Genesis 的轻量错误封装工具。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL