Adding index page with 404 catchall

This commit is contained in:
Armon Dadgar 2013-12-24 17:09:51 -08:00
parent 8cc761de17
commit 5c874584be
1 changed files with 11 additions and 0 deletions

View File

@ -52,6 +52,8 @@ func (s *HTTPServer) Shutdown() {
// registerHandlers is used to attach our handlers to the mux // registerHandlers is used to attach our handlers to the mux
func (s *HTTPServer) registerHandlers() { func (s *HTTPServer) registerHandlers() {
s.mux.HandleFunc("/", s.Index)
s.mux.HandleFunc("/v1/status/leader", s.wrap(s.StatusLeader)) s.mux.HandleFunc("/v1/status/leader", s.wrap(s.StatusLeader))
s.mux.HandleFunc("/v1/status/peers", s.wrap(s.StatusPeers)) s.mux.HandleFunc("/v1/status/peers", s.wrap(s.StatusPeers))
@ -96,6 +98,15 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
return f return f
} }
// Renders a simple index page
func (s *HTTPServer) Index(resp http.ResponseWriter, req *http.Request) {
if req.URL.Path == "/" {
resp.Write([]byte("Consul Agent"))
} else {
resp.WriteHeader(404)
}
}
// decodeBody is used to decode a JSON request body // decodeBody is used to decode a JSON request body
func decodeBody(req *http.Request, out interface{}) error { func decodeBody(req *http.Request, out interface{}) error {
dec := json.NewDecoder(req.Body) dec := json.NewDecoder(req.Body)