diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5srvWeb.go | 59 | ||||
-rwxr-xr-x | src/hub/test-client | 7 |
2 files changed, 65 insertions, 1 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go index c067737..281a4fe 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go +++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strconv" + "time" "github.com/zenazn/goji" "github.com/zenazn/goji/web" @@ -33,6 +34,62 @@ func (self StatsSinkServer) getSource(c web.C, w http.ResponseWriter, r *http.Re } } +func getFilter(r *http.Request) (filter StatsFilter) { + from := r.FormValue("from") + if from != "" { + fromT, err := time.Parse(time.RFC3339, from) + if err == nil { + filter.start = &fromT + } + } + + to := r.FormValue("to") + if to != "" { + toT, err := time.Parse(time.RFC3339, to) + if err == nil { + filter.end = &toT + } + } + + hostname := r.FormValue("hostname") + if hostname != "" { + filter.hostname = &hostname + } + + contentId := r.FormValue("contentId") + if contentId != "" { + filter.contentId = &contentId + } + + format := r.FormValue("format") + if format != "" { + filter.format = &format + } + + quality := r.FormValue("quality") + if quality != "" { + filter.quality = &quality + } + + return +} + +func (self StatsSinkServer) getUpdateList(c web.C, w http.ResponseWriter, r *http.Request) { + filter := getFilter(r) + updates, err := self.store.GetUpdates(&filter) + fmt.Fprintf(w, "Updates (%v): %v, %v", filter, updates, err) +} + +func (self StatsSinkServer) getUpdate(c web.C, w http.ResponseWriter, r *http.Request) { + id, err := strconv.ParseInt(c.URLParams["id"], 10, 64) + if err == nil { + src, err := self.store.GetUpdate(int(id)) + fmt.Fprintf(w, "Update: %v, %v, %v", id, src, err) + } else { + fmt.Fprintf(w, "Update: invalid id: %v", err) + } +} + func clientCount(c web.C, w http.ResponseWriter, r *http.Request) { } @@ -41,5 +98,7 @@ func (self StatsSinkServer) ServeWeb() { goji.Get("/tags", self.getTagList) goji.Get("/sources", self.getSourcesList) goji.Get("/sources/:id", self.getSource) + goji.Get("/updates", self.getUpdateList) + goji.Get("/updates/:id", self.getUpdate) goji.Serve() } diff --git a/src/hub/test-client b/src/hub/test-client index 335bab4..c9d7b91 100755 --- a/src/hub/test-client +++ b/src/hub/test-client @@ -1,3 +1,8 @@ #!/bin/sh -socat file:../../dat/sample.json,rdonly unix-client:/run/sfive/pipe +echo import sample.json +time 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 |