mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 05:32:20 +01:00
38 lines
992 B
Go
38 lines
992 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/Sean-Der/fail2go"
|
|
"github.com/gorilla/mux"
|
|
"net/http"
|
|
)
|
|
|
|
func globalStatusHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Fail2goConn) {
|
|
globalStatus, _ := fail2goConn.GlobalStatus()
|
|
|
|
encodedOutput, err := json.Marshal(globalStatus)
|
|
if err != nil {
|
|
}
|
|
|
|
res.Write(encodedOutput)
|
|
}
|
|
|
|
func globalPingHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Fail2goConn) {
|
|
globalPing, _ := fail2goConn.GlobalPing()
|
|
|
|
encodedOutput, err := json.Marshal(globalPing)
|
|
if err != nil {
|
|
}
|
|
|
|
res.Write(encodedOutput)
|
|
|
|
}
|
|
|
|
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")
|
|
}
|