-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathexample_test.go
More file actions
32 lines (26 loc) · 777 Bytes
/
Copy pathexample_test.go
File metadata and controls
32 lines (26 loc) · 777 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
25
26
27
28
29
30
31
32
package raft_test
import (
"io"
"net/http"
"github.com/shaj13/raft"
"github.com/shaj13/raft/transport"
"github.com/shaj13/raft/transport/raftgrpc"
"github.com/shaj13/raft/transport/rafthttp"
"google.golang.org/grpc"
)
type stateMachine struct{}
func (stateMachine) Apply([]byte) {}
func (stateMachine) Snapshot() (r io.ReadCloser, err error) { return }
func (stateMachine) Restore(io.ReadCloser) (err error) { return }
func Example_gRPC() {
srv := grpc.NewServer()
node := raft.NewNode(stateMachine{}, transport.GRPC)
raftgrpc.RegisterHandler(srv, node.Handler())
}
func Example_http() {
node := raft.NewNode(stateMachine{}, transport.HTTP)
handler := rafthttp.Handler(node.Handler())
_ = http.Server{
Handler: handler,
}
}