mirror of
https://github.com/therootcompany/golib.git
synced 2026-02-10 05:48:06 +00:00
f: add cmd/ssechat as ServerSentEvents demo
This commit is contained in:
parent
b6d8c2217a
commit
448ac5f1c2
@ -72,7 +72,13 @@ func handleSSE(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSE format: one data: line with the full JSON
|
// SSE format:
|
||||||
|
// : comment
|
||||||
|
// event: optional_name
|
||||||
|
// data: data
|
||||||
|
// data: more data
|
||||||
|
//
|
||||||
|
// : extra newline to end data
|
||||||
if msg.Event != "" {
|
if msg.Event != "" {
|
||||||
fmt.Fprintf(w, "event: %s\n", msg.Event)
|
fmt.Fprintf(w, "event: %s\n", msg.Event)
|
||||||
}
|
}
|
||||||
@ -83,11 +89,6 @@ func handleSSE(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleSend(w http.ResponseWriter, r *http.Request) {
|
func handleSend(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
http.Error(w, "Bad form", http.StatusBadRequest)
|
http.Error(w, "Bad form", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user