Files
xlgo-core/examples
杭州明婳科技 0c9f256dfc feat(v1.1.0): HA & Manager 化
对应体检报告 #10-#24,一次性完成 v1.1.0 全部 13 项:

- #10 storage/cache/redis/jwt/logger 五组件 Manager 化(XxxManager + DefaultXxx + SetDefaultXxxManager,包级 facade 保留兼容)
- #11 删除 wire 包 + 清理 StartServerWithPort/GracefulShutdown 双轨
- #12 Lifecycle Hooks(OnInit/OnStart/OnReady/OnStop)
- #13 Server 参数配置化(timeout/TLS/unix_socket/response_mode)
- #14 JWTConfig.Expire 改 time.Duration + 删 AppConfig.TokenExpire
- #15 response Mode 开关(ModeBusiness/ModeREST)
- #16 Config.Validate 启动期校验
- #17 livez/readyz 探针路由
- #18 Prometheus metrics 中间件 + /metrics
- #19 请求级 Timeout 中间件
- #21 主库探活 + replica 健康剔除
- #22 App.Go + in-flight goroutine 管理
- #24 RequestID 默认装入 + #23 核对

Breaking:删 wire、删 TokenExpire、JWTConfig.Expire 类型变更、删双轨函数。
详见 CHANGELOG 升级说明。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 10:41:05 +08:00
..
2026-06-23 10:41:05 +08:00
2026-06-22 23:21:59 +08:00
2026-06-22 23:21:59 +08:00

xlgo 示例

两个可运行示例,帮助快速上手 xlgo。

minimal — 最小 HTTP 服务

不依赖 MySQL / Redis / Storage,纯 HTTP + 健康检查。第一次接触 xlgo 从这里开始。

go run ./examples/minimal

访问 http://localhost:8081/health(健康检查)与 http://localhost:8081/api/v1/(示例路由)

full — 完整业务 API

包含 MySQL + Redis + JWT + 一个 user CRUD(登录发 token、认证路由、创建/查询用户)。

运行前需准备

  • MySQL(修改 examples/full/config.yamldatabase 配置)
  • Redis(修改 examples/full/config.yamlredis 配置)
go run ./examples/full

启动后自动迁移 user 表。接口:

方法 路径 说明 认证
POST /api/v1/login 登录,返回 token
GET /api/v1/users/:id 查询用户 是(Bearer token
POST /api/v1/users 创建用户 是(Bearer token

登录示例:

curl -X POST http://localhost:8082/api/v1/login \
  -H "Content-Type: application/json" \
  -d '{"username":"alice","password":"secret"}'

示例代码为演示用途,密码明文存储、未做参数校验,生产环境请使用 bcrypt 哈希密码并配合 validation 包校验入参。