Errors conforms to MarshalJSON interface

This commit is contained in:
Manu Mtz-Almeida
2015-05-22 18:34:42 +02:00
parent 9163ee543d
commit 4eeca21039
2 changed files with 17 additions and 1 deletions

View File

@ -6,6 +6,7 @@ package gin
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
)
@ -60,6 +61,10 @@ func (msg *Error) JSON() interface{} {
return json
}
func (msg *Error) MarshalJSON() ([]byte, error) {
return json.Marshal(msg.JSON())
}
func (msg *Error) Error() string {
return msg.Err.Error()
}
@ -113,6 +118,10 @@ func (a errorMsgs) JSON() interface{} {
}
}
func (a errorMsgs) MarshalJSON() ([]byte, error) {
return json.Marshal(a.JSON())
}
func (a errorMsgs) String() string {
if len(a) == 0 {
return ""