From: Scott Worley Date: Sat, 28 Jul 2012 17:24:14 +0000 (-0700) Subject: Decode URL parameters X-Git-Url: http://git.scottworley.com/reliable-chat/commitdiff_plain/87ac1d98245de076b321b149cf8c36795f4425e6?hp=--cc Decode URL parameters --- 87ac1d98245de076b321b149cf8c36795f4425e6 diff --git a/server/server.go b/server/server.go index a8b1c53..8c8a989 100644 --- a/server/server.go +++ b/server/server.go @@ -80,7 +80,17 @@ func start_store() Store { func start_server(store Store) { http.HandleFunc("/fetch", func(w http.ResponseWriter, r *http.Request) { - var since time.Time // TODO: Get start time from URL + var since time.Time + url_since := r.FormValue("since") + if url_since != "" { + err := json.Unmarshal([]byte(url_since), &since) + if err != nil { + log.Print("fetch: parse since: ", err) + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("Could not parse since as date")) + return + } + } messages_from_store := make(chan []Message, 1) store.Get <- StoreRequest{since, messages_from_store} @@ -95,8 +105,7 @@ func start_server(store Store) { }) http.HandleFunc("/speak", func(w http.ResponseWriter, r *http.Request) { - text := "woof" // TODO: Get text from URL - store.Add <- Message{time.Now(), text} + store.Add <- Message{time.Now(), r.FormValue("text")} }) log.Fatal(http.ListenAndServe(":8080", nil))