Skip to content

sse-io/sse.io-server-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSE-IO For Golang

Go Report CardGoDoc

Golang server for SSE-IO.

Install

go get github.com/sse-io/sse.io-server-go

How to use

Standalone server

httpAddr := flag.String("http.addr", fmt.Sprintf(":%d", 9001), "HTTP listen address")
path := "/files/:guid/pull"
server := sseio.NewSSEIO(sseio.SetPath(path))

eventHandler, _ := server.RegisterEventHandler("event",
    sseio.SetGetRoomIdFunc(func(context sseio.Context) string {
        return context.Params["guid"]
    }),
)

go func() {
    server.Listen(*httpAddr)
}()

eventHandler.SendMessage("guid1", "hello sseio")

attaching to your http server

you should install "github.com/gorilla/mux" first.

path := "/files/:guid/pull"
server := sseio.NewSSEIO()

// ... regist event handler

r := mux.NewRouter()
r.Handle(path, server).Methods("GET")
r.HandleFunc("/hello", func(resp http.ResponseWriter, request *http.Request) {
    fmt.Fprint(resp, "hello world")
})

go func() {
    http.ListenAndServe(*httpAddr, r)
}()

Documents

GoDoc

Releases

No releases published

Packages

No packages published

Languages