refactor: ♻️ 响应体中添加 success 字段

main
熊二 2 years ago
parent a5c6cc4045
commit 963d4aabf3
  1. 7
      app/net.go

@ -248,13 +248,18 @@ func (w *ResponseWriter) Error(err error) {
if len(message) == 0 { if len(message) == 0 {
message = http.StatusText(status) message = http.StatusText(status)
} }
w.Send(status, map[string]any{"code": code, "message": message}) w.Send(status, map[string]any{
"code": code,
"message": message,
"success": code == 0,
})
} }
func (w *ResponseWriter) Ok(data any, message ...string) { func (w *ResponseWriter) Ok(data any, message ...string) {
info := map[string]any{ info := map[string]any{
"code": 0, "code": 0,
"message": "ok", "message": "ok",
"success": true,
"data": data, "data": data,
} }
if len(message) > 0 { if len(message) > 0 {

Loading…
Cancel
Save