プロジェクト
概要
Go向けServer-Sent Events
その他のプロジェクト計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- 0
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルeventsource
eventsource provides server-sent events for net/http server.
Usage
SSE with default options
package main
import (
"gopkg.in/antage/eventsource.v1"
"log"
"net/http"
"strconv"
"time"
)
func main() {
es := eventsource.New(nil, nil)
defer es.Close()
http.Handle("/events", es)
go func() {
id := 1
for {
es.SendEventMessage("tick", "tick-event", strconv.Itoa(id))
id++
time.Sleep(2 * time.Second)
}
}()
log.Fatal(http.ListenAndServe(":8080", nil))
}
SSE with custom options
package main
import (
"gopkg.in/antage/eventsource.v1"
"log"
"net/http"
"strconv"
"time"
)
func main() {
es := eventsource.New(
&eventsource.Settings{
Timeout: 5 * time.Second,
CloseOnTimeout: false,
IdleTimeout: 30 * time.Minute,
}, nil)
es.SendRetryMessage(3 * time.Second)
defer es.Close()
http.Handle("/events", es)
go func() {
id := 1
for {
es.SendEventMessage("tick", "tick-event", strconv.Itoa(id))
id++
time.Sleep(2 * time.Second)
}
}()
log.Fatal(http.ListenAndServe(":8080", nil))
}
SSE with custom HTTP headers
package main
import (
"gopkg.in/antage/eventsource.v1"
"log"
"net/http"
"strconv"
"time"
)
func main() {
es := eventsource.New(
eventsource.DefaultSettings(),
func(req *http.Request) [][]byte {
return [][]byte{
[]byte("X-Accel-Buffering: no"),
[]byte("Access-Control-Allow-Origin: *"),
}
},
)
defer es.Close()
http.Handle("/events", es)
go func() {
id := 1
for {
es.SendEventMessage("tick", "tick-event", strconv.Itoa(id))
id++
time.Sleep(2 * time.Second)
}
}()
log.Fatal(http.ListenAndServe(":8080", nil))
}
関連プロジェクトを探す
読み込み中…