summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srvWeb.go27
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go35
2 files changed, 52 insertions, 10 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go
index 1b64c4b..c067737 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 (
"fmt"
"net/http"
+ "strconv"
"github.com/zenazn/goji"
"github.com/zenazn/goji/web"
@@ -12,7 +13,33 @@ func hello(c web.C, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", c.URLParams["name"])
}
+func (self StatsSinkServer) getTagList(c web.C, w http.ResponseWriter, r *http.Request) {
+ tags, err := self.store.GetTags()
+ fmt.Fprintf(w, "Tags: %v, err %v", tags, err)
+}
+
+func (self StatsSinkServer) getSourcesList(c web.C, w http.ResponseWriter, r *http.Request) {
+ sources, err := self.store.GetSources()
+ fmt.Fprintf(w, "Sources: %v, err %v", sources, err)
+}
+
+func (self StatsSinkServer) getSource(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.GetSource(int(id))
+ fmt.Fprintf(w, "Source: %v, %v, %v", id, src, err)
+ } else {
+ fmt.Fprintf(w, "Source: invalid id: %v", err)
+ }
+}
+
+func clientCount(c web.C, w http.ResponseWriter, r *http.Request) {
+}
+
func (self StatsSinkServer) ServeWeb() {
goji.Get("/hello/:name", hello)
+ goji.Get("/tags", self.getTagList)
+ goji.Get("/sources", self.getSourcesList)
+ goji.Get("/sources/:id", self.getSource)
goji.Serve()
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 57a5b82..e23c3db 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -326,10 +326,12 @@ func (s sqliteStore) Append(update StatisticsData) (err error) {
return tx.Commit()
}
-func (s sqliteStore) CountUpdateEntries(filter *StatsFilter) (count int64, err error) {
- sourceSql, parameters := getFilteredDataUpdateSelect(filter)
- count, err = s.db.SelectInt("select count(*) from "+sourceSql, parameters)
- return
+func castArrayToString(value []interface{}) []string {
+ res := make([]string, len(value))
+ for i := range value {
+ res[i] = value[i].(string)
+ }
+ return res
}
func (s sqliteStore) GetTags() ([]string, error) {
@@ -341,12 +343,26 @@ func (s sqliteStore) GetTags() ([]string, error) {
return nil, dbErr
}
-func castArrayToString(value []interface{}) []string {
- res := make([]string, len(value))
- for i := range value {
- res[i] = value[i].(string)
+func (s sqliteStore) GetSources() (res []sourceDb, err error) {
+ qres, err := s.db.Select(sourceDb{}, "select * from "+sourcesTn)
+ if err == nil {
+ res = make([]sourceDb, len(qres))
+ for i := range qres {
+ res[i] = *qres[i].(*sourceDb)
+ }
}
- return res
+ return
+}
+
+func (s sqliteStore) GetSource(id int) (res sourceDb, err error) {
+ err = s.db.SelectOne(&res, "select * from "+sourcesTn+" where Id = ?", id)
+ return
+}
+
+func (s sqliteStore) CountUpdateEntries(filter *StatsFilter) (count int64, err error) {
+ sourceSql, parameters := getFilteredDataUpdateSelect(filter)
+ count, err = s.db.SelectInt("select count(*) from "+sourceSql, parameters)
+ return
}
func (s sqliteStore) CountClients(filter *StatsFilter) uint {
@@ -360,7 +376,6 @@ type bpsQueryResult struct {
BytesSent uint
StartTime time.Time
LastStartTime time.Time
- LastDuration time.Duration
}
func (s sqliteStore) GetAverageBps(filter *StatsFilter) (uint, error) {