-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.go
42 lines (34 loc) · 844 Bytes
/
transport.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
package raftgrp
import (
"log"
etransport "github.com/EricYT/raftgrp/transport"
"go.etcd.io/etcd/pkg/types"
"go.etcd.io/etcd/raft/raftpb"
"go.uber.org/zap"
)
// ETCD interface
type Transporter interface {
Send(m []raftpb.Message)
AddPeer(id types.ID, urls []string)
RemovePeer(id types.ID)
RemoveAllPeers()
}
var _ Transporter = (*transport)(nil)
type transport struct {
etransport.Transport
r func([]raftpb.Message) ([]raftpb.Message, error)
}
func NewTransport(t etransport.Transport, r func([]raftpb.Message) ([]raftpb.Message, error)) *transport {
return &transport{
Transport: t,
r: r,
}
}
// Rendering payload
func (t *transport) Send(ms []raftpb.Message) {
var err error
if ms, err = t.r(ms); err != nil {
log.Fatal("[transport] rendering messages error ", zap.Error(err))
}
t.Transport.Send(ms)
}