feat(app): 添加测试功能并增强错误处理
- 在应用路由中新增 test 接口用于显示测试数据 - 引入 errors 包以支持错误处理机制 - 在上下文响应处理中集成错误对象设置 - 实现 JSON 错误消息的自动转换与存储 - 扩展响应结构以同时支持 result 和 error 字段
This commit is contained in:
parent
3fd0975427
commit
9949231d7c
@ -3,6 +3,7 @@ package hotime
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -59,6 +60,9 @@ func (that *Context) Display(statu int, data interface{}) {
|
|||||||
resp["result"] = temp
|
resp["result"] = temp
|
||||||
//兼容android等需要json转对象的服务
|
//兼容android等需要json转对象的服务
|
||||||
resp["error"] = temp
|
resp["error"] = temp
|
||||||
|
|
||||||
|
that.Error.SetError(errors.New(resp.ToJsonString()))
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
resp["result"] = data
|
resp["result"] = data
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,9 @@ func main() {
|
|||||||
appIns.Run(Router{
|
appIns.Run(Router{
|
||||||
"app": {
|
"app": {
|
||||||
"test": {
|
"test": {
|
||||||
|
"test": func(that *Context) {
|
||||||
|
that.Display(2, "dsadasd")
|
||||||
|
},
|
||||||
// 测试入口 - 运行所有测试
|
// 测试入口 - 运行所有测试
|
||||||
"all": func(that *Context) {
|
"all": func(that *Context) {
|
||||||
results := Map{}
|
results := Map{}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user