-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoints.go
47 lines (36 loc) · 1.08 KB
/
endpoints.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
package deamon
import (
"context"
"log"
hubrpc "github.com/Mihalic2040/Hub-rpc"
"github.com/Mihalic2040/Hub-rpc/src/proto/api"
"github.com/Mihalic2040/Hub-Mobile/protocols"
)
func (s *Service) Peers(ctx context.Context, req *protocols.PeersResponse) (*protocols.PeersResponse, error) {
// Implement the logic to handle the gRPC request and return a response
return &protocols.PeersResponse{Peers: "s.App.Host.Peerstore().Peers().String()"}, nil
}
// request
func (s *Service) Request(ctx context.Context, req *protocols.RequestData) (*protocols.ResponseData, error) {
data := api.Request{
Payload: req.Payload,
User: req.User,
Handler: req.Handler,
}
log.Println(len(s.host.Peerstore().Peers()))
resp, err := hubrpc.NewRequest(s.contex, req.Peer, &data, s.cfg.ProtocolId, *s.dht, s.host)
if err != nil {
return &protocols.ResponseData{
Payload: err.Error(),
Status: 0,
}, nil
}
return &protocols.ResponseData{
Payload: resp.Payload,
Status: resp.Status,
}, nil
// return &protocols.ResponseData{
// Payload: "resp.Payload",
// Status: 43,
// }, nil
}