mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-11 20:43:44 +08:00
完善文档
This commit is contained in:
@@ -10,9 +10,9 @@ import (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// JsonExit 返回JSON数据并退出当前HTTP执行函数
|
||||
@@ -21,6 +21,36 @@ func JsonExit(r *ghttp.Request, code int, message string, data ...interface{}) {
|
||||
r.Exit()
|
||||
}
|
||||
|
||||
// RXml xml
|
||||
func RXml(r *ghttp.Request, code int, message string, data ...interface{}) {
|
||||
responseData := interface{}(nil)
|
||||
if len(data) > 0 {
|
||||
responseData = data[0]
|
||||
}
|
||||
res := &model.Response{
|
||||
Code: code,
|
||||
Message: message,
|
||||
Timestamp: gtime.Timestamp(),
|
||||
TraceID: gctx.CtxId(r.Context()),
|
||||
}
|
||||
|
||||
// 如果不是正常的返回,则将data转为error
|
||||
if gcode.CodeOK.Code() == code {
|
||||
res.Data = responseData
|
||||
} else {
|
||||
res.Error = responseData
|
||||
}
|
||||
|
||||
// 清空响应
|
||||
r.Response.ClearBuffer()
|
||||
|
||||
// 写入响应
|
||||
r.Response.WriteXml(gconv.Map(res))
|
||||
|
||||
// 加入到上下文
|
||||
contexts.SetResponse(r.Context(), res)
|
||||
}
|
||||
|
||||
// RJson 标准返回结果数据结构封装
|
||||
func RJson(r *ghttp.Request, code int, message string, data ...interface{}) {
|
||||
responseData := interface{}(nil)
|
||||
@@ -30,7 +60,7 @@ func RJson(r *ghttp.Request, code int, message string, data ...interface{}) {
|
||||
res := &model.Response{
|
||||
Code: code,
|
||||
Message: message,
|
||||
Timestamp: time.Now().Unix(),
|
||||
Timestamp: gtime.Timestamp(),
|
||||
TraceID: gctx.CtxId(r.Context()),
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user