X-Git-Url: http://git.scottworley.com/reliable-chat/blobdiff_plain/03513e5ce2d22d140752efeb3aefa72266bd9d87..c3983543f7453a81573a496168049edb38a5d223:/server/server.go diff --git a/server/server.go b/server/server.go index a328785..f19cefc 100644 --- a/server/server.go +++ b/server/server.go @@ -11,6 +11,7 @@ import "time" var port = flag.Int("port", 21059, "Port to listen on") +var frame_count = expvar.NewInt("frame_count") var speak_count = expvar.NewInt("speak_count") var fetch_count = expvar.NewInt("fetch_count") var fetch_wait_count = expvar.NewInt("fetch_wait_count") @@ -18,6 +19,7 @@ var fetch_wake_count = expvar.NewInt("fetch_wake_count") type Message struct { Time time.Time + ID string Text string } @@ -94,6 +96,48 @@ func start_store() Store { return store } +const frame_html = ` + + + + + + + + +` + func start_server(store Store) { http.HandleFunc("/fetch", func(w http.ResponseWriter, r *http.Request) { var since time.Time @@ -121,13 +165,22 @@ func start_server(store Store) { }) http.HandleFunc("/speak", func(w http.ResponseWriter, r *http.Request) { - store.Add <- &Message{time.Now(), r.FormValue("text")} + store.Add <- &Message{ + time.Now(), + r.FormValue("id"), + r.FormValue("text")} + }) + + http.HandleFunc("/frame", func(w http.ResponseWriter, r *http.Request) { + frame_count.Add(1) + w.Write([]byte(frame_html)); }) - log.Fatal(http.ListenAndServe(":" + strconv.Itoa(*port), nil)) + log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), nil)) } func main() { + flag.Parse() store := start_store() start_server(store) }