marshalJSON works like json.Marshal but with HTML-escaping disabled
(v interface{})
| 120 | |
| 121 | // marshalJSON works like json.Marshal but with HTML-escaping disabled |
| 122 | func marshalJSON(v interface{}) ([]byte, error) { |
| 123 | buf := bytes.Buffer{} |
| 124 | enc := json.NewEncoder(&buf) |
| 125 | enc.SetEscapeHTML(false) |
| 126 | if err := enc.Encode(v); err != nil { |
| 127 | return nil, err |
| 128 | } |
| 129 | bb := buf.Bytes() |
| 130 | // omit trailing newline added by json.Encoder |
| 131 | if len(bb) > 0 && bb[len(bb)-1] == '\n' { |
| 132 | return bb[:len(bb)-1], nil |
| 133 | } |
| 134 | return bb, nil |
| 135 | } |