WriteJSON writes the JSON encoding of v as a message. See the documentation for encoding/json Marshal for details about the conversion of Go values to JSON.
(v interface{})
| 21 | // See the documentation for encoding/json Marshal for details about the |
| 22 | // conversion of Go values to JSON. |
| 23 | func (c *Conn) WriteJSON(v interface{}) error { |
| 24 | w, err := c.NextWriter(TextMessage) |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | err1 := json.NewEncoder(w).Encode(v) |
| 29 | err2 := w.Close() |
| 30 | if err1 != nil { |
| 31 | return err1 |
| 32 | } |
| 33 | return err2 |
| 34 | } |
| 35 | |
| 36 | // ReadJSON reads the next JSON-encoded message from the connection and stores |
| 37 | // it in the value pointed to by v. |