forked from prysmaticlabs/prysm
/
allocations.go
39 lines (35 loc) · 873 Bytes
/
allocations.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
package main
import (
"fmt"
"io"
"net/http"
)
func (s *server) serveAllocationsHTTPPage() {
mux := http.NewServeMux()
mux.HandleFunc("/allocations", func(w http.ResponseWriter, _ *http.Request) {
res := ""
a, err := s.db.Allocations()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
if _, err := io.WriteString(w, err.Error()); err != nil {
log.Error(err)
}
return
}
for podName, pubkeys := range a {
for _, pk := range pubkeys {
res += fmt.Sprintf("%s=%#x\n", podName, pk)
}
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusOK)
if _, err := io.WriteString(w, res); err != nil {
log.Error(err)
}
})
srv := &http.Server{Addr: ":8080", Handler: mux}
go func() {
log.Fatal(srv.ListenAndServe())
}()
log.Info("Serving allocations page at :8080/allocations")
}