X-Git-Url: http://git.scottworley.com/reliable-chat/blobdiff_plain/86945f8d2e10192da9f9ad7f5678f382d83b55fd..a69e0831f99b9f46bfd7116da4eb0f8b37e67073:/server/server.go diff --git a/server/server.go b/server/server.go index 5837032..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)) } func main() { + flag.Parse() store := start_store() start_server(store) }