From 9949231d7c6238e22a70ebb70bee8453e17863e1 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Sat, 31 Jan 2026 02:05:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=8A=9F=E8=83=BD=E5=B9=B6=E5=A2=9E=E5=BC=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在应用路由中新增 test 接口用于显示测试数据 - 引入 errors 包以支持错误处理机制 - 在上下文响应处理中集成错误对象设置 - 实现 JSON 错误消息的自动转换与存储 - 扩展响应结构以同时支持 result 和 error 字段 --- context.go | 4 ++++ example/main.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/context.go b/context.go index b14c816..ca56c43 100644 --- a/context.go +++ b/context.go @@ -3,6 +3,7 @@ package hotime import ( "bytes" "encoding/json" + "errors" "io" "mime/multipart" "net/http" @@ -59,6 +60,9 @@ func (that *Context) Display(statu int, data interface{}) { resp["result"] = temp //兼容android等需要json转对象的服务 resp["error"] = temp + + that.Error.SetError(errors.New(resp.ToJsonString())) + } else { resp["result"] = data } diff --git a/example/main.go b/example/main.go index 9b7d943..3ccffe3 100644 --- a/example/main.go +++ b/example/main.go @@ -20,6 +20,9 @@ func main() { appIns.Run(Router{ "app": { "test": { + "test": func(that *Context) { + that.Display(2, "dsadasd") + }, // 测试入口 - 运行所有测试 "all": func(that *Context) { results := Map{}