summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-22 18:55:33 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-22 18:55:33 +0200
commit993e24ed33066e75d6f971cb7ec36a11603dd79e (patch)
tree664b0653834326f4823734ca3b1a2650cff5992f /src/hub
parenthub: prepare db schema update (diff)
hub: add basic POST support
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvWeb.go20
-rwxr-xr-xsrc/hub/test-client10
2 files changed, 27 insertions, 3 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
index 0aa1426..d2367fa 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
@@ -3,6 +3,7 @@ package sfive
import (
"encoding/json"
"fmt"
+ "io/ioutil"
"net/http"
"strconv"
"time"
@@ -91,6 +92,24 @@ func (self StatsSinkServer) getUpdate(c web.C, w http.ResponseWriter, r *http.Re
}
}
+func (self StatsSinkServer) postUpdate(c web.C, w http.ResponseWriter, r *http.Request) {
+ decoder := NewPlainDecoder()
+
+ buffer, err := ioutil.ReadAll(r.Body)
+ if err != nil {
+ s5l.Printf("web: failed to read post value: %v\n", err)
+ return
+ }
+
+ data, err := decoder.Decode(buffer)
+ if err != nil {
+ s5l.Printf("web: failed to decode: %v\ndat:%v", err, string(buffer))
+ return
+ }
+
+ self.appendData <- data
+}
+
func (self StatsSinkServer) getStats(c web.C, w http.ResponseWriter, r *http.Request) {
filter := getFilter(r)
stats, err := self.store.GetStats(&filter)
@@ -116,6 +135,7 @@ func (self StatsSinkServer) ServeWeb() {
goji.Get("/sources/:id", self.getSource)
goji.Get("/updates", self.getUpdateList)
goji.Get("/updates/:id", self.getUpdate)
+ goji.Post("/updates", self.postUpdate)
goji.Get("/stats", self.getStats)
goji.Serve()
}
diff --git a/src/hub/test-client b/src/hub/test-client
index c9d7b91..0696bc5 100755
--- a/src/hub/test-client
+++ b/src/hub/test-client
@@ -1,8 +1,12 @@
#!/bin/sh
echo import sample.json
-time socat file:../../dat/sample.json,rdonly unix-client:/run/sfive/pipe
-
+socat file:../../dat/sample.json,rdonly unix-client:/run/sfive/pipe
echo show query result
-wget -q -S -O - 'http://localhost:8000/updates?from=2013-10-24T05:00:00Z&to=2013-10-24T00:05:20Z
+wget -q -S -O - 'http://localhost:8000/updates?from=2013-10-24T05:00:00Z&to=2013-10-24T00:05:20Z'
+
+echo '\npost update'
+wget --post-file='../../dat/sample-post.json' 'http://localhost:8000/updates'
+
+echo '\ndone'