Help us shape the future of Go! Take the 2026 Go Developer Survey

hertz

module
v0.3.6 Latest Latest
Warning

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

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

README

hertz

Hertz 运行时集成——日志桥接/生命周期/SSE/适配器/追踪

🌐 项目主页:https://oekit.github.io/ · 名称由来:Open Easy Kit(开源 · 易用 · 工具集合) 🤖 AI Agent:本仓规范与硬规则见 AGENTS.md;机器可读索引见 llms.txt(接口签名以源码为准)。

安装

go get github.com/oekit/hertz@v0.3.5

这个仓库做什么

hertz 是 Hertz 运行时集成:把 CloudWeGo Hertz 接进 oekit 的日志、生命周期、 可观测体系,并提供注册发现适配与框架侧追踪。

组成

包 做什么
hertz hlog → logx 日志桥接(caller 归属已修正)、RunServer 生命周期接入、AddShutdownHook、优雅退出语义
hertz/health 健康检查路由(对接 bootstrap/healthz)
hertz/metrics /metrics 端点
hertz/sse SSE 流式推送(官方 protocol/sse 封装)
hertz/render / hertz/adaptor 渲染与适配辅助
registry/hertz Hertz 注册发现适配器(对接 oekit/registry)
nns/hertz NNS 适配器(发现 + 注册,含降级链)
governance/hertz 动态限流/超时中间件(消费 core/governance 配置)
…/hertzotel …/hertztracer OTel / OpenTracing 服务端追踪(二选一)

快速使用

import (
    hertzserver "github.com/cloudwego/hertz/pkg/app/server"
    ekithertz "github.com/oekit/hertz/hertz"
)

h := hertzserver.New(hertzserver.WithHostPorts(":8080"))
// ...路由
ekithertz.RunServer(app, "my-service", h) // 接入 bootstrap 生命周期,优雅关闭

要点

  • hlog.SetLogger(ekithertz.NewLogger(logx.NewSlogLogger("svc"))) 框架日志进 logx(caller 已修正)
  • server.WithExitWaitTime:排空上限(默认 5s),有长耗时请求调大并保持 < K8s 宽限期
  • 自定义中间件栈在 middleware;CRUD handler 在 handler

矩阵总览(23 活跃模块,自动生成)

模块 内容 矩阵内依赖
pkg 微工具集 18 合 1(errors/validator/stringx/slicex/enumx/convert/encoding/jsonrepair/httpjson/mathx/pathx/pagination/ptrx/timex/uidgen/cache/bufiox/strmap) —
concurrency 并发与流控原语(async/gopool/group/singleflight/progress/syncx/ratelimit/retry) —
logx 统一日志门面(多后端可替换 + Sink + caller 归属)+ 优雅关停 —
core 应用基建件(governance 治理 schema / config 配置加载 / lifecycle 契约 / network IP 工具 / version) logx
istio Istio Proxyless——Kitex xDS 动态熔断 —
metrics Prometheus 门面 + 弹性指标族 core
tracing OpenTelemetry 追踪 + trace_id 真相源 logx
registry 注册发现核心 + Nacos 实现 + Nacos 配置源 + sdbridge core、logx
data 缓存检查器(TTL/failTTL/inflight 合并)+ LocalCache concurrency、logx
gorm SQL/GORM 全家——连接池增强、框架无关 CRUD Service、仓储 logx、pkg
redis Redis 全家——客户端封装、缓存后端、分布式锁 concurrency、data、logx
httpx HTTP 客户端 + 负载均衡——服务发现/熔断/重试/指标/OTel 透传 concurrency、core、logx、metrics、registry、tracing
network 轻量网络客户端——WebSocket/NATS/MQ 抽象、连接与流工具、Octopus 推送 concurrency、logx、tracing
timertask 分片定时任务(FNV-1a、心跳续约) concurrency、logx
middleware Hertz 自研标准中间件栈 + contrib 桥接 + hmw concurrency、core、logx、metrics、pkg、registry、tracing
nns NNS 服务治理客户端——provider 无关发现/配置/实例缓存 concurrency、core、logx、registry
nns-endpoint NNS 端点工厂——per-service 熔断、换实例重试、gRPC 池 concurrency、core、httpx、logx、metrics、nns、registry
bootstrap 应用生命周期引导——bootstrap.Run 骨架 + healthz concurrency、logx
handler HTTP handler 层——通用 CRUD Handler、参数绑定、版本端点 concurrency、core、gorm、logx、metrics、middleware、pkg、registry、tracing
hertz Hertz 运行时集成——日志桥接、生命周期、SSE/health/metrics、适配器、OTel bootstrap、concurrency、core、logx、metrics、nns、registry、tracing
kitex Kitex 生态——日志桥接、治理热更、生命周期、BizError 桥接、kitexotel bootstrap、concurrency、core、logx、metrics、nns、pkg、registry
workflow 组合式流程编排——串行/并行/异步/条件分支 + Hook AOP concurrency、logx
kitex-examples Kitex echo 示例——client/server + IDL + 治理配置 bootstrap、concurrency、core、kitex、logx、metrics、nns、pkg、registry、tracing

依赖严格自底向上;微库已合并为 pkg,旧微库仓已删除。

本仓在矩阵中的位置与依赖见上表「矩阵内依赖」列。历史沿革:源自 ekit 单体库 (git.enjoye.top/enjoydream/ekit v0.34.0,冻结维护),2026-10 拆分为独立 module。

License

MIT — 见 LICENSE

Directories

Path Synopsis
governance
hertz
Package govhertz 把 governance.Store 消费成 hertz server 治理中间件 (audit 5.2 阶段 1:hertz 侧治理)。
Package govhertz 把 governance.Store 消费成 hertz server 治理中间件 (audit 5.2 阶段 1:hertz 侧治理)。
Package hertz 为 Hertz HTTP 框架提供 ekit 生态集成。
Package hertz 为 Hertz HTTP 框架提供 ekit 生态集成。
adaptor
Package adaptor 提供 hertz-contrib/adaptor 常用 helper,让 ekit 业务 用 1 行代码把 net/http 生态(http.FileServer / embed.FS / gorilla/websocket)接入 hertz。
Package adaptor 提供 hertz-contrib/adaptor 常用 helper,让 ekit 业务 用 1 行代码把 net/http 生态(http.FileServer / embed.FS / gorilla/websocket)接入 hertz。
health
Package health 提供 Hertz 健康检查端点。
Package health 提供 Hertz 健康检查端点。
metrics
Package metrics 提供 Hertz Prometheus 指标端点。
Package metrics 提供 Hertz Prometheus 指标端点。
render
Package render 提供业务特定的 hertz Render interface 实现,与 hertz 官方 render 子包(https://www.cloudwego.io/zh/docs/hertz/tutorials/basic-feature/render/) 风格一致。
Package render 提供业务特定的 hertz Render interface 实现,与 hertz 官方 render 子包(https://www.cloudwego.io/zh/docs/hertz/tutorials/basic-feature/render/) 风格一致。
sse
Package sse 提供 Hertz SSE(Server-Sent Events)封装。
Package sse 提供 Hertz SSE(Server-Sent Events)封装。
nns
hertz
Package hertz 提供 nns 与 CloudWeGo Hertz 集成的适配器。
Package hertz 提供 nns 与 CloudWeGo Hertz 集成的适配器。
observability
tracing/instrumentation/hertzotel
Package hertzotel 提供 Hertz HTTP client/server 的 OpenTelemetry tracing 集成 helper,桥接 hertz-contrib/obs-opentelemetry/tracing。
Package hertzotel 提供 Hertz HTTP client/server 的 OpenTelemetry tracing 集成 helper,桥接 hertz-contrib/obs-opentelemetry/tracing。
tracing/instrumentation/hertztracer
Package hertztracer 提供 Hertz HTTP client/server 的 OpenTracing tracing 集成 helper,桥接 hertz-contrib/tracer。
Package hertztracer 提供 Hertz HTTP client/server 的 OpenTracing tracing 集成 helper,桥接 hertz-contrib/tracer。
registry
hertz
Package hertz 提供 ekit registry 抽象到 CloudWeGo Hertz 框架的适配器。
Package hertz 提供 ekit registry 抽象到 CloudWeGo Hertz 框架的适配器。

Jump to

Keyboard shortcuts

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