docs(agent): 统一中文注释并补充部署文档
将代码与测试注释改为中文以符合仓库规范;新增中文部署指南、 示例配置,并完善构建脚本对 VERSION 注入的说明。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,24 +7,24 @@ import (
|
||||
"mfd-monitor-agent/internal/status"
|
||||
)
|
||||
|
||||
// Provider supplies the latest cached HostStatus to HTTP handlers.
|
||||
// Provider 向 HTTP 处理器提供最新缓存的 HostStatus。
|
||||
type Provider interface {
|
||||
// Get returns the latest snapshot and whether a snapshot is ready.
|
||||
// Get 返回最新快照及快照是否已就绪。
|
||||
Get() (status.HostStatus, bool)
|
||||
}
|
||||
|
||||
// StaticProvider is a test provider with a fixed snapshot response.
|
||||
// StaticProvider 是用于测试的固定快照提供者。
|
||||
type StaticProvider struct {
|
||||
Snapshot status.HostStatus
|
||||
OK bool
|
||||
}
|
||||
|
||||
// Get returns the configured static snapshot and readiness flag.
|
||||
// Get 返回配置的静态快照与就绪标志。
|
||||
func (p StaticProvider) Get() (status.HostStatus, bool) {
|
||||
return p.Snapshot, p.OK
|
||||
}
|
||||
|
||||
// New creates the HTTP API handler for health and status endpoints.
|
||||
// New 创建提供 health 与 status 端点的 HTTP API 处理器。
|
||||
func New(provider Provider) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -61,7 +61,7 @@ func New(provider Provider) http.Handler {
|
||||
return mux
|
||||
}
|
||||
|
||||
// writeJSON serializes value as JSON with a response status code.
|
||||
// writeJSON 以给定状态码将 value 序列化为 JSON 响应。
|
||||
func writeJSON(w http.ResponseWriter, code int, value any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(code)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"mfd-monitor-agent/internal/status"
|
||||
)
|
||||
|
||||
// TestStatusReturnsCachedSnapshot verifies /status reads the provider cache.
|
||||
// TestStatusReturnsCachedSnapshot 验证 /status 读取提供者缓存。
|
||||
func TestStatusReturnsCachedSnapshot(t *testing.T) {
|
||||
provider := StaticProvider{Snapshot: status.HostStatus{
|
||||
Agent: status.AgentInfo{Version: "test", SnapshotAt: time.Now(), SnapshotStatus: "ok"},
|
||||
@@ -34,7 +34,7 @@ func TestStatusReturnsCachedSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestHealthReportsSnapshotMetadata verifies /health returns snapshot metadata.
|
||||
// TestHealthReportsSnapshotMetadata 验证 /health 返回快照元数据。
|
||||
func TestHealthReportsSnapshotMetadata(t *testing.T) {
|
||||
provider := StaticProvider{Snapshot: status.HostStatus{
|
||||
Agent: status.AgentInfo{Version: "test", SnapshotAt: time.Unix(10, 0), SnapshotStatus: "partial"},
|
||||
@@ -57,7 +57,7 @@ func TestHealthReportsSnapshotMetadata(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusReturnsServiceUnavailableBeforeSnapshot verifies /status does not live collect.
|
||||
// TestStatusReturnsServiceUnavailableBeforeSnapshot 验证 /status 不会在请求时实时采集。
|
||||
func TestStatusReturnsServiceUnavailableBeforeSnapshot(t *testing.T) {
|
||||
server := New(StaticProvider{OK: false})
|
||||
|
||||
@@ -70,7 +70,7 @@ func TestStatusReturnsServiceUnavailableBeforeSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestHealthReturnsStartingBeforeSnapshot verifies /health exposes startup state.
|
||||
// TestHealthReturnsStartingBeforeSnapshot 验证 /health 在启动阶段暴露 starting 状态。
|
||||
func TestHealthReturnsStartingBeforeSnapshot(t *testing.T) {
|
||||
server := New(StaticProvider{OK: false})
|
||||
|
||||
@@ -90,7 +90,7 @@ func TestHealthReturnsStartingBeforeSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusRejectsNonGET verifies /status only accepts GET requests.
|
||||
// TestStatusRejectsNonGET 验证 /status 仅接受 GET 请求。
|
||||
func TestStatusRejectsNonGET(t *testing.T) {
|
||||
server := New(StaticProvider{OK: true})
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestStatusRejectsNonGET(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestHealthRejectsNonGET verifies /health only accepts GET requests.
|
||||
// TestHealthRejectsNonGET 验证 /health 仅接受 GET 请求。
|
||||
func TestHealthRejectsNonGET(t *testing.T) {
|
||||
server := New(StaticProvider{OK: true})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user