forked from antage/eventsource
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged github's README and .gitignore
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
# Ignore Sublime Text 2 files | ||
/*.sublime-* | ||
|
||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
*.so | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
|
||
_testmain.go | ||
|
||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# eventsource | ||
|
||
Server-sent events for Go. | ||
|
||
Package eventsource provides server-sent events for net/http server. | ||
|
||
## Usage | ||
|
||
``` go | ||
package main | ||
|
||
import ( | ||
"eventsource" | ||
"log" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func main() { | ||
es := eventsource.New() | ||
defer es.Close() | ||
http.Handle("/events", es) | ||
go func() { | ||
id := 1 | ||
for { | ||
es.SendMessage("tick", "tick-event", strconv.Itoa(id)) | ||
id++ | ||
time.Sleep(2 * time.Second) | ||
} | ||
}() | ||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
} | ||
``` |