]> git.scottworley.com Git - reliable-chat/commitdiff
Decode URL parameters
authorScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 17:24:14 +0000 (10:24 -0700)
committerScott Worley <sworley@chkno.net>
Sat, 28 Jul 2012 17:24:14 +0000 (10:24 -0700)
server/server.go

index a8b1c5334f3a778370d4ed58f00a1503fe3bb23e..8c8a9893d61360dd00f3ea643871fe7fb33339d2 100644 (file)
@@ -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))