Render (SecureJSON) marshals the given interface object and writes it with custom ContentType.
(w http.ResponseWriter)
| 92 | |
| 93 | // Render (SecureJSON) marshals the given interface object and writes it with custom ContentType. |
| 94 | func (r SecureJSON) Render(w http.ResponseWriter) error { |
| 95 | r.WriteContentType(w) |
| 96 | jsonBytes, err := json.API.Marshal(r.Data) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | // if the jsonBytes is array values |
| 101 | if bytes.HasPrefix(jsonBytes, bytesconv.StringToBytes("[")) && bytes.HasSuffix(jsonBytes, |
| 102 | bytesconv.StringToBytes("]")) { |
| 103 | if _, err = w.Write(bytesconv.StringToBytes(r.Prefix)); err != nil { |
| 104 | return err |
| 105 | } |
| 106 | } |
| 107 | _, err = w.Write(jsonBytes) |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | // WriteContentType (SecureJSON) writes JSON ContentType. |
| 112 | func (r SecureJSON) WriteContentType(w http.ResponseWriter) { |