@@ -62,41 +62,43 @@ func respJSONWithStatusCode(c *gin.Context, code int, msg string, data ...interf
6262 writeJSON (c , code , resp )
6363}
6464
65- // Output return json data by http status code
66- func Output (c * gin.Context , code int , msg ... interface {}) {
65+ // Output standard HTTP status codes and data
66+ func Output (c * gin.Context , code int , data ... interface {}) {
6767 switch code {
6868 case http .StatusOK :
69- respJSONWithStatusCode (c , http .StatusOK , "ok" , msg ... )
69+ respJSONWithStatusCode (c , http .StatusOK , "ok" , data ... )
7070 case http .StatusBadRequest :
71- respJSONWithStatusCode (c , http .StatusBadRequest , errcode .InvalidParams .Msg (), msg ... )
71+ respJSONWithStatusCode (c , http .StatusBadRequest , errcode .InvalidParams .Msg (), data ... )
7272 case http .StatusUnauthorized :
73- respJSONWithStatusCode (c , http .StatusUnauthorized , errcode .Unauthorized .Msg (), msg ... )
73+ respJSONWithStatusCode (c , http .StatusUnauthorized , errcode .Unauthorized .Msg (), data ... )
7474 case http .StatusForbidden :
75- respJSONWithStatusCode (c , http .StatusForbidden , errcode .Forbidden .Msg (), msg ... )
75+ respJSONWithStatusCode (c , http .StatusForbidden , errcode .Forbidden .Msg (), data ... )
7676 case http .StatusNotFound :
77- respJSONWithStatusCode (c , http .StatusNotFound , errcode .NotFound .Msg (), msg ... )
77+ respJSONWithStatusCode (c , http .StatusNotFound , errcode .NotFound .Msg (), data ... )
7878 case http .StatusRequestTimeout :
79- respJSONWithStatusCode (c , http .StatusRequestTimeout , errcode .Timeout .Msg (), msg ... )
79+ respJSONWithStatusCode (c , http .StatusRequestTimeout , errcode .Timeout .Msg (), data ... )
8080 case http .StatusConflict :
81- respJSONWithStatusCode (c , http .StatusConflict , errcode .Conflict .Msg (), msg ... )
81+ respJSONWithStatusCode (c , http .StatusConflict , errcode .Conflict .Msg (), data ... )
8282 case http .StatusInternalServerError :
83- respJSONWithStatusCode (c , http .StatusInternalServerError , errcode .InternalServerError .Msg (), msg ... )
83+ respJSONWithStatusCode (c , http .StatusInternalServerError , errcode .InternalServerError .Msg (), data ... )
8484 case http .StatusTooManyRequests :
85- respJSONWithStatusCode (c , http .StatusTooManyRequests , errcode .LimitExceed .Msg (), msg ... )
85+ respJSONWithStatusCode (c , http .StatusTooManyRequests , errcode .LimitExceed .Msg (), data ... )
8686 case http .StatusServiceUnavailable :
87- respJSONWithStatusCode (c , http .StatusServiceUnavailable , errcode .ServiceUnavailable .Msg (), msg ... )
87+ respJSONWithStatusCode (c , http .StatusServiceUnavailable , errcode .ServiceUnavailable .Msg (), data ... )
8888
8989 default :
90- respJSONWithStatusCode (c , code , http .StatusText (code ), msg ... )
90+ respJSONWithStatusCode (c , code , http .StatusText (code ), data ... )
9191 }
9292}
9393
94- // Out return json data by http status code, converted by errcode
94+ // Out HTTP standard status code which is converted from errcode.Error
9595func Out (c * gin.Context , err * errcode.Error , data ... interface {}) {
9696 code := err .ToHTTPCode ()
9797 switch code {
9898 case http .StatusOK :
9999 respJSONWithStatusCode (c , http .StatusOK , "ok" , data ... )
100+ case http .StatusInternalServerError :
101+ respJSONWithStatusCode (c , http .StatusInternalServerError , err .Msg (), data ... )
100102 case http .StatusBadRequest :
101103 respJSONWithStatusCode (c , http .StatusBadRequest , err .Msg (), data ... )
102104 case http .StatusUnauthorized :
@@ -109,8 +111,6 @@ func Out(c *gin.Context, err *errcode.Error, data ...interface{}) {
109111 respJSONWithStatusCode (c , http .StatusRequestTimeout , err .Msg (), data ... )
110112 case http .StatusConflict :
111113 respJSONWithStatusCode (c , http .StatusConflict , err .Msg (), data ... )
112- case http .StatusInternalServerError :
113- respJSONWithStatusCode (c , http .StatusInternalServerError , err .Msg (), data ... )
114114 case http .StatusTooManyRequests :
115115 respJSONWithStatusCode (c , http .StatusTooManyRequests , err .Msg (), data ... )
116116 case http .StatusServiceUnavailable :
0 commit comments