diff --git a/cnnl-service/src/main.rs b/cnnl-service/src/main.rs index 0ff365c..d684d2d 100644 --- a/cnnl-service/src/main.rs +++ b/cnnl-service/src/main.rs @@ -394,6 +394,229 @@ async fn handle_version(_state: web::Data) -> impl Responder { HttpResponse::Ok().json(ApiResponse::ok(version, 0)) } + +// ============================================================ +// 根路径 - API 文档页面 +// ============================================================ +async fn handle_root() -> impl Responder { + let html = r#" + + + + + NAC CNNL 编译服务 + + + +
+
+ +
宪政神经网络语言编译服务
+
v0.1.0 · 运行中
+
+ +
+

API 端点

+
+
+ POST +
+
/api/v1/compile
+
编译 CNNL 源代码,生成 NVM 字节码和宪法状态文件
+
+
+
+ POST +
+
/api/v1/parse
+
解析 CNNL 源代码,返回抽象语法树(AST)
+
+
+
+ POST +
+
/api/v1/validate
+
验证 CNNL 语法正确性,不生成字节码
+
+
+
+ GET +
+
/api/v1/health
+
服务健康检查,返回运行状态和运行时长
+
+
+
+ GET +
+
/api/v1/version
+
服务版本信息
+
+
+
+
+ +
+

快速示例

+
+# 编译一个 CNNL 条款 +curl -X POST https://cnnl.newassetchain.io/api/v1/compile \ + -H "Content-Type: application/json" \ + -d '{ + "source": "clause XTZH_GOLD_COVERAGE {\n level: eternal\n title: \"黄金储备覆盖率底线\"\n parameter XTZH_GOLD_COVERAGE_MIN: f64 = 1.25\n}", + "generate_state": true + }' +
+
+ +
+

服务信息

+
+
+
服务名称
+
nac-cnnl-service
+
+
+
编译器版本
+
CNNL v0.1.0
+
+
+
目标虚拟机
+
NVM (NAC VM)
+
+
+
协议
+
HTTPS / TLS 1.3
+
+
+
+ + +
+ +"#; + HttpResponse::Ok() + .content_type("text/html; charset=utf-8") + .body(html) +} + // ============================================================ // 主函数 // ============================================================ @@ -420,6 +643,7 @@ async fn main() -> std::io::Result<()> { .app_data(app_state.clone()) .app_data(web::JsonConfig::default().limit(1024 * 1024)) // 1MB 请求体限制 // API 路由 + .route("/", web::get().to(handle_root)) .route("/api/v1/compile", web::post().to(handle_compile)) .route("/api/v1/parse", web::post().to(handle_parse)) .route("/api/v1/validate", web::post().to(handle_validate))