Skip to content

Commit a5fbeee

Browse files
committed
chore: 完善系统消息
1 parent 643b84a commit a5fbeee

File tree

4 files changed

+393
-15
lines changed

4 files changed

+393
-15
lines changed

context.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ func (p *Context) Body() []byte {
415415
if err != nil {
416416
return nil
417417
}
418-
419-
// 重新赋值
420418
p.Request.Body = io.NopCloser(bytes.NewBuffer(body))
421419

422420
return body
@@ -731,11 +729,9 @@ func (p *Context) JSONOk(message ...interface{}) error {
731729
content = ""
732730
data interface{}
733731
)
734-
735732
if len(message) == 1 {
736733
content = message[0].(string)
737734
}
738-
739735
if len(message) == 2 {
740736
content = message[0].(string)
741737
data = message[1]
@@ -744,9 +740,40 @@ func (p *Context) JSONOk(message ...interface{}) error {
744740
return p.JSON(200, Success(content, data))
745741
}
746742

747-
// 输出失败状态的JSON数据,JSONError("错误")
748-
func (p *Context) JSONError(message string) error {
749-
return p.JSON(200, Error(message))
743+
// 输出失败状态的JSON数据,JSONError("错误") | JSONError("错误", map[string]interface{}{"title":"标题"})
744+
func (p *Context) JSONError(message ...interface{}) error {
745+
var (
746+
code = 10001
747+
content = ""
748+
data interface{}
749+
)
750+
if len(message) == 1 {
751+
content = message[0].(string)
752+
}
753+
if len(message) == 2 {
754+
content = message[0].(string)
755+
data = message[1]
756+
}
757+
758+
return p.JSON(200, Error(code, content, data))
759+
}
760+
761+
// 根据Code输出失败状态的JSON数据,JSONErrorByCode(10001) | JSONErrorByCode(10001, map[string]interface{}{"title":"标题"})
762+
func (p *Context) JSONErrorByCode(message ...interface{}) error {
763+
var (
764+
code = 10001
765+
content = ""
766+
data interface{}
767+
)
768+
if len(message) == 1 {
769+
code = message[0].(int)
770+
}
771+
if len(message) == 2 {
772+
code = message[0].(int)
773+
data = message[1]
774+
}
775+
776+
return p.JSON(200, Error(code, content, data))
750777
}
751778

752779
// 执行下一个Use方法,TODO

engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
AppName = "QuarkGo"
2323

2424
// 版本号
25-
Version = "3.8.5"
25+
Version = "3.8.6"
2626

2727
// 包名
2828
PkgName = "github.com/quarkcloudio/quark-go/v3"

0 commit comments

Comments
 (0)