Implement global/bans returns the contents of the Bans table from the persistent database introduced in 0.9.0

This commit is contained in:
Sean DuBois 2014-07-16 05:20:33 +00:00
parent 05ec165128
commit 4a19482e20

View file

@ -25,11 +25,21 @@ func globalPingHandler(res http.ResponseWriter, req *http.Request, fail2goConn *
return return
} }
encodedOutput, _ := json.Marshal(globalPing) encodedOutput, _ := json.Marshal(globalPing)
res.Write(encodedOutput) res.Write(encodedOutput)
} }
func globalBansHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
globalBans, err := fail2goConn.GlobalBans()
if err != nil {
writeHTTPError(res, err)
return
}
encodedOutput, _ := json.Marshal(globalBans)
res.Write(encodedOutput)
}
func globalHandler(globalRouter *mux.Router, fail2goConn *fail2go.Conn) { func globalHandler(globalRouter *mux.Router, fail2goConn *fail2go.Conn) {
globalRouter.HandleFunc("/status", func(res http.ResponseWriter, req *http.Request) { globalRouter.HandleFunc("/status", func(res http.ResponseWriter, req *http.Request) {
globalStatusHandler(res, req, fail2goConn) globalStatusHandler(res, req, fail2goConn)
@ -37,4 +47,8 @@ func globalHandler(globalRouter *mux.Router, fail2goConn *fail2go.Conn) {
globalRouter.HandleFunc("/ping", func(res http.ResponseWriter, req *http.Request) { globalRouter.HandleFunc("/ping", func(res http.ResponseWriter, req *http.Request) {
globalPingHandler(res, req, fail2goConn) globalPingHandler(res, req, fail2goConn)
}).Methods("GET") }).Methods("GET")
globalRouter.HandleFunc("/bans", func(res http.ResponseWriter, req *http.Request) {
globalBansHandler(res, req, fail2goConn)
}).Methods("GET")
} }