时间服务器

一个轻量级的Go服务,通过stdio、HTTP/JSON-RPC或Server-Sent Events (SSE)提供当前UTC时间。

  • by crivetimihai
  • Go
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 crivetimihai/mcp-fast-time-server-go

使用说明

🦫 快速时间服务器

作者:Mihai Criveti 一种最小的Go服务,用于流式传输或返回当前UTC时间 标准输入输出, HTTP/JSON-RPC,或 服务器发送事件(SSE).


特性

  • 三种运输方式: stdio, http (JSON‑RPC 2.0), and sse
  • 单静态二进制(~2MiB)
  • 通过以下方式生成时间版本和日期 main.appVersion, main.buildDate
  • 跨平台构建通过 make cross
  • 轻量级容器的Dockerfile
  • Linting(golangci-lint, staticcheck)以及预提交支持
  • 具有HTML覆盖率和Go基准的单元测试
  • 负载测试支持 使用 hey

快速开始

git clone https://github.com/yourorg/fast-time-server.git
cd fast-time-server

# Build & run over stdio
make run

# HTTP JSON‑RPC on port 8080
make run-http

# SSE endpoint on port 8080
make run-sse

安装

需要Go 1.23+。

go install github.com/yourorg/fast-time-server@latest

也可作为版本提供。

CLI标志

标志 默认值 描述
-transport stdio 选项: stdio, http, sse, dual
-addr/-listen 0.0.0.0 HTTP/SSE的绑定地址
-port 8080 HTTP/SSE/双端口
-auth-token (空) SSE身份验证的承载令牌

api参考

HTTP(JSON-RPC 2.0)

发布 /http

请求:

{"jsonrpc":"2.0","method":"Time.Now","id":1}

答复:

{"jsonrpc":"2.0","result":"2025-06-21T12:34:56Z","id":1}

SSE

获取 /sse (可选标题: Authorization: Bearer <token>)

每秒输出UTC时间戳:

data: 2025-06-21T12:34:56Z

负载测试

安装流行的HTTP负载测试仪 嘿:

brew install hey            # macOS
wget https://hey-release... # Linux prebuilt binary

运行快速负载测试:

# 500 requests total, 50 concurrent, HTTP transport
hey -n 500 -c 50 http://localhost:8080/http

生成详细的CSV输出以供分析:

hey -n 1000 -c 100 -o csv http://localhost:8080/http > results.csv

码头工人

make docker-build
make docker-run           # HTTP mode

交叉编译

make cross

二进制出现在 dist/fast-time-server-<os>-<arch>.

发展

任务 命令
格式和整洁 make fmt tidy
毛皮和兽医 make lint staticcheck vet
运行预提交钩子 make pre-commit

测试和基准测试

make test       # Unit tests (race detection)
make coverage   # HTML coverage report
make bench      # Go benchmarks

许可证

Apache 2.0