-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.go
62 lines (53 loc) · 1.63 KB
/
monitor.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
56
57
58
59
60
61
62
package main
import (
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"github.com/michaelklishin/rabbit-hole"
"net/http"
"reflect"
"strings"
)
func accessControl(f http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type")
if r.Method == "OPTIONS" {
return
}
f(w, r)
}
}
func queue_detailsfetcher(w http.ResponseWriter, r *http.Request){
rmqc, _ := rabbithole.NewClient("", "", "")
file := strings.TrimPrefix(r.RequestURI, "/details/")
q, err := rmqc.GetQueue("/", file)
fmt.Println(q)
if err != nil{
fmt.Println(err)
}
fmt.Println(reflect.TypeOf(q))
b, err := json.Marshal(q)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Connection", "close")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type, Authorization")
if r.Method == "OPTIONS" {
return
}
w.WriteHeader(http.StatusOK)
w.Write(b)
}
func main() {
r := mux.NewRouter()
root_subrouter := r.PathPrefix("/").Subrouter()
root_subrouter.Methods("GET").Name("Health").Path("/healthz").Handler(accessControl(func(writer http.ResponseWriter, r *http.Request) {
writer.WriteHeader(http.StatusOK)
writer.Write([]byte("OK"))
}))
fetch_subrouter := r.PathPrefix("/details").Subrouter()
fetch_subrouter.HandleFunc("/{queue_name}", queue_detailsfetcher)
http.ListenAndServe(":8081", r)
}