Skip to content

Commit

Permalink
new /stats handler
Browse files Browse the repository at this point in the history
  • Loading branch information
vbehar committed Sep 4, 2015
1 parent 76b362f commit 934266d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
18 changes: 18 additions & 0 deletions web/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package web

import (
"encoding/json"
"net/http"

"github.com/julienschmidt/httprouter"
)

// StatsHandler answers HTTP requests with the stats in JSON format
func (c *Context) StatsHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
s, err := json.Marshal(c.Stats.Data())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
w.Write(s)
}
4 changes: 2 additions & 2 deletions web/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (d *Data) Title() string {
return "openshift-dashboard"
}

// Home answers HTTP requests by loading data for all resource types and using the "home" view
func (c *Context) Home(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
// HomeHandler answers HTTP requests by loading data for all resource types and using the "home" view
func (c *Context) HomeHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
d, err := c.ClientWrapper.LoadData(api.ResourceTypeAll...)
if err != nil {
fmt.Fprintf(w, "failed to load data: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func RunHttpServer() {
c := NewContext()

router := httprouter.New()
router.GET("/", c.Home)
router.GET("/", c.HomeHandler)
router.GET("/stats", c.StatsHandler)

n := negroni.New(
negroni.NewRecovery(),
Expand Down

0 comments on commit 934266d

Please sign in to comment.