2014-06-16 05:38:10 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/Sean-Der/fail2go"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2014-06-18 07:53:54 +02:00
|
|
|
func globalStatusHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Fail2goConn) {
|
|
|
|
globalStatus, _ := fail2goConn.GlobalStatus()
|
2014-06-16 05:38:10 +02:00
|
|
|
|
|
|
|
encodedOutput, err := json.Marshal(globalStatus)
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Write(encodedOutput)
|
|
|
|
}
|
|
|
|
|
2014-06-18 07:53:54 +02:00
|
|
|
func globalPingHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Fail2goConn) {
|
|
|
|
globalPing, _ := fail2goConn.GlobalPing()
|
2014-06-16 05:38:10 +02:00
|
|
|
|
|
|
|
encodedOutput, err := json.Marshal(globalPing)
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
|
|
|
|
res.Write(encodedOutput)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-18 07:53:54 +02:00
|
|
|
func globalHandler(globalRouter *mux.Router, fail2goConn *fail2go.Fail2goConn) {
|
|
|
|
globalRouter.HandleFunc("/status", func(res http.ResponseWriter, req *http.Request) {
|
|
|
|
globalStatusHandler(res, req, fail2goConn)
|
|
|
|
}).Methods("GET")
|
|
|
|
globalRouter.HandleFunc("/ping", func(res http.ResponseWriter, req *http.Request) {
|
|
|
|
globalPingHandler(res, req, fail2goConn)
|
|
|
|
}).Methods("GET")
|
2014-06-16 05:38:10 +02:00
|
|
|
}
|