docs(agent): 统一中文注释并补充部署文档
将代码与测试注释改为中文以符合仓库规范;新增中文部署指南、 示例配置,并完善构建脚本对 VERSION 注入的说明。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -14,19 +14,19 @@ import (
|
||||
|
||||
const defaultRetryDelay = 2 * time.Second
|
||||
|
||||
// Provider supplies the cached HostStatus used for outbound reports.
|
||||
// Provider 提供用于外发上报的缓存 HostStatus。
|
||||
type Provider interface {
|
||||
// Get returns the latest snapshot and whether a snapshot is ready.
|
||||
// Get 返回最新快照及快照是否已就绪。
|
||||
Get() (status.HostStatus, bool)
|
||||
}
|
||||
|
||||
// Client posts HostStatus snapshots to a configured center endpoint.
|
||||
// Client 将 HostStatus 快照 POST 到配置的中心端地址。
|
||||
type Client struct {
|
||||
endpoint string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// NewClient creates a reporting client with the provided endpoint and request timeout.
|
||||
// NewClient 使用给定端点与请求超时创建上报客户端。
|
||||
func NewClient(endpoint string, timeout time.Duration) *Client {
|
||||
return &Client{
|
||||
endpoint: endpoint,
|
||||
@@ -34,7 +34,7 @@ func NewClient(endpoint string, timeout time.Duration) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
// Report posts one HostStatus snapshot as JSON and returns non-2xx responses as errors.
|
||||
// Report 将一份 HostStatus 以 JSON POST 上报;非 2xx 响应作为错误返回。
|
||||
func (c *Client) Report(snapshot status.HostStatus) error {
|
||||
body, err := json.Marshal(snapshot)
|
||||
if err != nil {
|
||||
@@ -56,12 +56,12 @@ func (c *Client) Report(snapshot status.HostStatus) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run periodically posts the latest cached snapshot until ctx is canceled.
|
||||
// Run 在 ctx 取消前按间隔 POST 最新缓存快照。
|
||||
func Run(ctx context.Context, provider Provider, client *Client, interval time.Duration, logger *slog.Logger) {
|
||||
runWithRetryDelay(ctx, provider, client, interval, defaultRetryDelay, logger)
|
||||
}
|
||||
|
||||
// runWithRetryDelay runs the reporting loop and retries one failed report after retryDelay.
|
||||
// runWithRetryDelay 运行上报循环;单次失败后按 retryDelay 重试一次。
|
||||
func runWithRetryDelay(ctx context.Context, provider Provider, client *Client, interval time.Duration, retryDelay time.Duration, logger *slog.Logger) {
|
||||
ticker := time.NewTicker(interval)
|
||||
defer ticker.Stop()
|
||||
@@ -81,7 +81,7 @@ func runWithRetryDelay(ctx context.Context, provider Provider, client *Client, i
|
||||
}
|
||||
}
|
||||
|
||||
// reportWithRetry posts a snapshot and performs one cancellation-aware retry on failure.
|
||||
// reportWithRetry 上报快照;失败时在可取消的等待后重试一次。
|
||||
func reportWithRetry(ctx context.Context, client *Client, snapshot status.HostStatus, retryDelay time.Duration) error {
|
||||
err := client.Report(snapshot)
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user