docs: consolidate runnable examples and publish v0.1.1 guides

This commit is contained in:
2026-09-24 21:27:25 +08:00
parent e29dec717f
commit 81e56bd633
124 changed files with 1430 additions and 281 deletions

29
examples/health/README.md Normal file
View File

@@ -0,0 +1,29 @@
# 健康检查
查询存活、数据库/迁移就绪状态与运行版本。
## 准备
- Go 1.27.1、当前版本 Orbit;服务启动和初始化见[仓库 README](../../README.md#快速开始)。
- 无需凭据;服务地址必须可达。
- [示例总索引](../README.md)提供统一初始化和权限说明;完整字段、失败处理见[详细手册](../../docs/api/health.md)。
## 运行
以下命令从仓库根目录执行;凭据路径替换为实际初始化输出。
```sh
cd examples
export ORBIT_URL=http://127.0.0.1:8080
go run ./health
```
## 结果核对
liveness=alive readiness=ready scope=database_and_schema。具体 ID 和统计值以本次运行为准。程序会核对上述关键条件,失败时打印错误并以非零状态退出。
## 接入自己的项目
阅读[main.go](main.go)中的客户端创建、请求及错误处理。业务项目通过 `go get git.yuntuo.hk/k2safe/orbit/sdk/go@v0.1.1` 引入 SDK,无需导入本示例包。
本例只读,不创建任务、队列或订阅。

37
examples/health/main.go Normal file
View File

@@ -0,0 +1,37 @@
// Run against a started bootstrap server: ORBIT_URL=http://127.0.0.1:8080 go run ./health
package main
import (
"context"
"fmt"
orbit "git.yuntuo.hk/k2safe/orbit/sdk/go"
"log"
"os"
"time"
)
func main() {
address := os.Getenv("ORBIT_URL")
if address == "" {
address = "http://127.0.0.1:8080"
}
client, err := orbit.NewClient(address, orbit.Options{})
if err != nil {
log.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
live, err := client.Liveness(ctx)
if err != nil {
log.Fatal(err)
}
ready, err := client.Readiness(ctx)
if err != nil {
log.Fatal(err)
}
version, err := client.Version(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("liveness=%s readiness=%s scope=%s version=%s revision=%s\n", live.Status, ready.Status, ready.Scope, version.Version, version.Revision)
}