-
Notifications
You must be signed in to change notification settings - Fork 24
/
global.go
55 lines (45 loc) · 1.43 KB
/
global.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"github.com/sean-der/fail2go"
)
func globalStatusHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
globalStatus, err := fail2goConn.GlobalStatus()
if err != nil {
writeHTTPError(res, err)
return
}
encodedOutput, _ := json.Marshal(globalStatus)
res.Write(encodedOutput)
}
func globalPingHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
globalPing, err := fail2goConn.GlobalPing()
if err != nil {
writeHTTPError(res, err)
return
}
encodedOutput, _ := json.Marshal(globalPing)
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) {
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")
globalRouter.HandleFunc("/bans", func(res http.ResponseWriter, req *http.Request) {
globalBansHandler(res, req, fail2goConn)
}).Methods("GET")
}