Prechádzať zdrojové kódy

Use WriteJSON and ReadJSON on Conn struct.

Craig Jackson 12 rokov pred
rodič
commit
8e0dcebbf0
2 zmenil súbory, kde vykonal 4 pridanie a 4 odobranie
  1. 2 2
      json.go
  2. 2 2
      json_test.go

+ 2 - 2
json.go

@@ -12,7 +12,7 @@ import (
 //
 // See the documentation for encoding/json Marshal for details about the
 // conversion of Go values to JSON.
-func WriteJSON(c *Conn, v interface{}) error {
+func (c *Conn) WriteJSON(v interface{}) error {
 	w, err := c.NextWriter(TextMessage)
 	if err != nil {
 		return err
@@ -30,7 +30,7 @@ func WriteJSON(c *Conn, v interface{}) error {
 //
 // See the documentation for the encoding/json Marshal function for details
 // about the conversion of JSON to a Go value.
-func ReadJSON(c *Conn, v interface{}) error {
+func (c *Conn) ReadJSON(v interface{}) error {
 	_, r, err := c.NextReader()
 	if err != nil {
 		return err

+ 2 - 2
json_test.go

@@ -23,11 +23,11 @@ func TestJSON(t *testing.T) {
 	expect.A = 1
 	expect.B = "hello"
 
-	if err := WriteJSON(wc, &expect); err != nil {
+	if err := wc.WriteJSON(&expect); err != nil {
 		t.Fatal("write", err)
 	}
 
-	if err := ReadJSON(rc, &actual); err != nil {
+	if err := rc.ReadJSON(&actual); err != nil {
 		t.Fatal("read", err)
 	}