浏览代码

Update .travis.yml, update README.md and add support for gin-gonic/gin/pull/781

Javier Provecho Fernandez 9 年之前
父节点
当前提交
22d885f9ec
共有 3 个文件被更改,包括 25 次插入7 次删除
  1. 11 2
      .travis.yml
  2. 9 4
      README.md
  3. 5 1
      sse-encoder.go

+ 11 - 2
.travis.yml

@@ -1,6 +1,15 @@
 language: go
 sudo: false
 go:
-  - 1.3
-  - 1.4
+  - 1.6.4
+  - 1.7.4
   - tip
+
+git:
+  depth: 3
+
+script:
+  - go test -v -covermode=count -coverprofile=coverage.out
+
+after_success:
+  - bash <(curl -s https://codecov.io/bash)

+ 9 - 4
README.md

@@ -1,11 +1,16 @@
-#Server-Sent Events [![GoDoc](https://godoc.org/github.com/gin-contrib/sse?status.svg)](https://godoc.org/github.com/gin-contrib/sse) [![Build Status](https://travis-ci.org/gin-contrib/sse.svg)](https://travis-ci.org/gin-contrib/sse)
+# Server-Sent Events
+
+[![GoDoc](https://godoc.org/github.com/gin-contrib/sse?status.svg)](https://godoc.org/github.com/gin-contrib/sse)
+[![Build Status](https://travis-ci.org/gin-contrib/sse.svg)](https://travis-ci.org/gin-contrib/sse)
+[![codecov](https://codecov.io/gh/gin-contrib/sse/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-contrib/sse)
+[![Go Report Card](https://goreportcard.com/badge/github.com/gin-contrib/sse)](https://goreportcard.com/report/github.com/gin-contrib/sse)
 
 Server-sent events (SSE) is a technology where a browser receives automatic updates from a server via HTTP connection. The Server-Sent Events EventSource API is [standardized as part of HTML5[1] by the W3C](http://www.w3.org/TR/2009/WD-eventsource-20091029/).
 
 - [Read this great SSE introduction by the HTML5Rocks guys](http://www.html5rocks.com/en/tutorials/eventsource/basics/)
 - [Browser support](http://caniuse.com/#feat=eventsource)
 
-##Sample code
+## Sample code
 
 ```go
 import "github.com/gin-contrib/sse"
@@ -39,7 +44,7 @@ data: {"content":"hi!","date":1431540810,"user":"manu"}
  
 ```
 
-##Content-Type
+## Content-Type
 
 ```go
 fmt.Println(sse.ContentType)
@@ -48,6 +53,6 @@ fmt.Println(sse.ContentType)
 text/event-stream
 ```
 
-##Decoding support
+## Decoding support
 
 There is a client-side implementation of SSE coming soon.

+ 5 - 1
sse-encoder.go

@@ -87,13 +87,17 @@ func writeData(w stringWriter, data interface{}) error {
 }
 
 func (r Event) Render(w http.ResponseWriter) error {
+	r.WriteContentType(w)
+	return Encode(w, r)
+}
+
+func (r Event) WriteContentType(w http.ResponseWriter) {
 	header := w.Header()
 	header["Content-Type"] = contentType
 
 	if _, exist := header["Cache-Control"]; !exist {
 		header["Cache-Control"] = noCache
 	}
-	return Encode(w, r)
 }
 
 func kindOfData(data interface{}) reflect.Kind {