Explorar el Código

Conforms to new Render API

Manu Mtz-Almeida hace 10 años
padre
commit
c142f0f1ba
Se han modificado 2 ficheros con 6 adiciones y 3 borrados
  1. 1 1
      sse-encoder.go
  2. 5 2
      sse_test.go

+ 1 - 1
sse-encoder.go

@@ -80,7 +80,7 @@ func writeData(w stringWriter, data interface{}) error {
 	return nil
 	return nil
 }
 }
 
 
-func (r Event) Write(w http.ResponseWriter) error {
+func (r Event) Render(w http.ResponseWriter) error {
 	header := w.Header()
 	header := w.Header()
 	header["Content-Type"] = contentType
 	header["Content-Type"] = contentType
 
 

+ 5 - 2
sse_test.go

@@ -156,7 +156,7 @@ func TestRenderSSE(t *testing.T) {
 	err := (Event{
 	err := (Event{
 		Event: "msg",
 		Event: "msg",
 		Data:  "hi! how are you?",
 		Data:  "hi! how are you?",
-	}).Write(w)
+	}).Render(w)
 
 
 	assert.NoError(t, err)
 	assert.NoError(t, err)
 	assert.Equal(t, w.Body.String(), "event: msg\ndata: hi! how are you?\n\n")
 	assert.Equal(t, w.Body.String(), "event: msg\ndata: hi! how are you?\n\n")
@@ -172,7 +172,7 @@ func BenchmarkResponseWriter(b *testing.B) {
 		(Event{
 		(Event{
 			Event: "new_message",
 			Event: "new_message",
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
-		}).Write(w)
+		}).Render(w)
 	}
 	}
 }
 }
 
 
@@ -187,6 +187,7 @@ func BenchmarkFullSSE(b *testing.B) {
 			Retry: 10,
 			Retry: 10,
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
 		})
 		})
+		buf.Reset()
 	}
 	}
 }
 }
 
 
@@ -200,6 +201,7 @@ func BenchmarkNoRetrySSE(b *testing.B) {
 			Id:    "13435",
 			Id:    "13435",
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
 		})
 		})
+		buf.Reset()
 	}
 	}
 }
 }
 
 
@@ -212,5 +214,6 @@ func BenchmarkSimpleSSE(b *testing.B) {
 			Event: "new_message",
 			Event: "new_message",
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
 			Data:  "hi! how are you? I am fine. this is a long stupid message!!!",
 		})
 		})
+		buf.Reset()
 	}
 	}
 }
 }