File size: 681 Bytes
48511d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package peers

import (
	"encoding/json"
	"net/http"
)

type PeerHandler struct {
	peerService *PeerService
}

func NewPeerHandler(peerService *PeerService) *PeerHandler {
	return &PeerHandler{
		peerService: peerService,
	}
}

func (h *PeerHandler) ListTrustedPeers(w http.ResponseWriter, r *http.Request) {
	if r.Method != http.MethodGet {
		http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
		return
	}

	peers, err := h.peerService.ListTrustedPeers()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(peers)
}