-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.go
More file actions
24 lines (22 loc) · 745 Bytes
/
Copy pathhttp.go
File metadata and controls
24 lines (22 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package shiftlock
import (
"encoding/json"
"net/http"
)
// DiagnosticsHandler returns an http.Handler that serves sanitized coordinator
// diagnostics as JSON. It does not start a server; mount it on your own mux.
// No secrets or backend credentials are included.
func DiagnosticsHandler(c *Coordinator) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
d := c.Diagnostics()
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "no-store")
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
_ = enc.Encode(d)
})
}