Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

zeus

CI Coverage Go Version License Security Policy Contributing Discussions

零依赖、可插拔的 Go 微服务框架。现代构造器注入模式 + 内置默认装配 + 4 层渐进暴露 API。

设计哲学

内部复杂(灵活)+ 外部简单(默认)。

用户 5 行代码启动应用,需要时能挖到底层实现细节。

详见 CLAUDE.md - 设计目标

快速开始(L1 入口)

package main

import (
    "net/http"

    "github.com/go-zeus/zeus/app"
)

func main() {
    app.Run(&app.Config{Port: 8080}, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("hello from zeus"))
    }))
}

// curl http://localhost:8080

零配置自动启用:

  • slog logger → stdout
  • recovery + requestid + accesslog 中间件
  • memory 注册中心 + 自动注册
  • 优雅关闭(SIGTERM/SIGINT,10s 超时)

4 层渐进暴露 API

用户 入口
L1 学习者 / 单进程 demo app.Run(cfg, handler) 5 行启动
L2 个人开发者 / 配置驱动 app.Run(cfgWithRegistry, handler) URL scheme
L3 小团队 / 代码定制 app.NewApp(opts ...AppOption) Option 类型装配
L4 定制需求 / 完全控制 components.NewApp(comps ...any) 声明式组件装配

L2:切换注册中心 / 灰度发布

app.Run(&app.Config{
    Name:     "my-service",
    Port:     8080,
    Cluster:  "canary",                    // 灰度集群
    Registry: "etcd://localhost:2379",     // 切换到 etcd(需 import 对应 plugin)
}, handler)

L3:类型装配(Option)

a := app.NewApp(
    app.AddServer(http.NewHTTP(http.Port(8080), http.Mux(handler))),
    app.WithRegistry(memory.New()),
    app.WithMiddleware(recovery.New()),
    app.WithServiceCluster("canary"),
)
a.Run()

L4:声明式组件装配(永久逃生通道)

app := components.NewApp(
    components.NewLogComponent(slog.NewSlog()),
    components.NewRegistryComponent(memory.New()),
    components.NewServerComponent(http.NewHTTP(http.Mux(mux))),
    components.NewServiceComponent(),
)
app.Run()

主要功能域

内置实现 plugins 实现
registry registry/memory plugins/registry/etcd
config config/file plugins/config/etcd,k8s
server server/http plugins/server/grpc
client client plugins/client/grpc
log log/slog plugins/log/zap
metrics metrics/noop plugins/metrics/prometheus
trace trace/noop plugins/trace/otel
proxy proxy(HTTP/WS/SSE) plugins/proxy/grpc
encoding encoding/json plugins/encoding/protobuf
middleware recovery/timeout/clustering/requestid/accesslog plugins/middleware/tracing,metrics
circuitbreaker circuitbreaker/counter(按 cluster 隔离)
ratelimit ratelimit/token(按 cluster 隔离)
retry retry/exponential(按 cluster 路由)
propagation propagation(W3C Baggage 兼容)
routing routing(X-Zeus-Cluster 端到端路由)
job job/interval(固定间隔) plugins/job/cron(cron 表达式)
mq mq/memory(进程内事件总线) plugins/mq/kafkanats
database database/sql(薄封装 stdlib) plugins/database/mysql/postgres
cache cache/memory(TTL 双路径清理) plugins/cache/redis

URL scheme 切换实现

各功能域支持通过 URL 字符串切换实现(与 import _ 副作用注册配合):

入口 已注册 scheme
registry app.resolveRegistry memory / etcd / nacos
cache cache.NewFromURL memory / redis
database database.NewFromURL mysql / postgres / sqlite
mq mq.NewBrokerFromURL memory / kafka / nats
job job.NewSchedulerFromURL interval / cron

构建

go test ./...                                  # 主包测试
go test -race -coverprofile=coverage.out ./...  # 主包覆盖率
cd examples && go build ./...                   # 示例构建

CI:.github/workflows/ci.yml — lint + test + build,覆盖主包和所有 plugins。

示例

社区

  • 💬 Discussions — 提问、想法讨论、最佳实践
  • 📝 Issues — Bug 报告、功能请求
  • 🤝 Contributing — 贡献指南(PR 流程 / 代码规范 / 测试要求)
  • 📜 Code of Conduct — 行为准则
  • 🔒 Security Policy — 安全漏洞披露流程
  • 📚 设计文档 — 4 层 API 设计哲学、概念分层、组件装配
  • 🌐 文档站 — Hugo 源(hugo server 本地预览 / 推 main 自动部署到 GitHub Pages)
  • 🔧 API 稳定性 — 🔒稳定 / 🧪实验 / 🔬内部分级

治理

文件 用途
CHANGELOG.md 每版本变更记录(breaking / feature / fix)
SECURITY.md 漏洞披露政策与响应 SLA
site/content/reference/api-stability.md API 稳定性分级清单
site/content/reference/plugin-bom.md 插件依赖版本治理策略
site/content/reference/optimization-plan.md 业界标杆对比 + 路线图

致谢

Zeus 的设计参考了以下优秀框架,但未直接复制代码:

  • kratos — BFF / 微服务架构思路
  • go-zero — 工程化与代码生成
  • gin — 路由与中间件链
  • kitex — RPC 治理与扩展点
  • Go 标准库net/http / database/sql / log/slog

详见 CLAUDE.md - 设计参考

许可证

MIT

About

零依赖、可插拔的 Go 微服务框架。构造器注入 + 内置默认装配 + 4 层渐进暴露 API。

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages