Added a new command 'weave status', implemented via an http listener #11

This commit is contained in:
Bryan Boreham committed 2014-08-29 14:44:50 +01:00
1 parent 81e8a9b987
commit a113da0e34
4 files changed
+60 -5

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package weave
import (
"fmt"
"net/http"
)
/* A simple http responder that will show the status of the router when asked,
e.g. via http://172.17.0.2/status
*/
type HttpStatusResponder struct {
router *Router
}
func NewHttpStatusResponder(router *Router) *HttpStatusResponder {
resp := &HttpStatusResponder{router}
return resp
}
func (resp *HttpStatusResponder) SetRouter(newRouter *Router) {
resp.router = newRouter
}
func (resp *HttpStatusResponder) ListenAndServe() {
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
if resp.router != nil {
fmt.Fprint(w, resp.router.Status())
} else {
fmt.Fprintf(w, "Not initialized")
}
})
address := fmt.Sprintf(":%d", StatusPort)
http.ListenAndServe(address, nil)
}