@@ -415,8 +415,6 @@ func (p *Context) Body() []byte {
415
415
if err != nil {
416
416
return nil
417
417
}
418
-
419
- // 重新赋值
420
418
p .Request .Body = io .NopCloser (bytes .NewBuffer (body ))
421
419
422
420
return body
@@ -731,11 +729,9 @@ func (p *Context) JSONOk(message ...interface{}) error {
731
729
content = ""
732
730
data interface {}
733
731
)
734
-
735
732
if len (message ) == 1 {
736
733
content = message [0 ].(string )
737
734
}
738
-
739
735
if len (message ) == 2 {
740
736
content = message [0 ].(string )
741
737
data = message [1 ]
@@ -744,9 +740,40 @@ func (p *Context) JSONOk(message ...interface{}) error {
744
740
return p .JSON (200 , Success (content , data ))
745
741
}
746
742
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 ))
750
777
}
751
778
752
779
// 执行下一个Use方法,TODO
0 commit comments