Skip to content

Commit

Permalink
fix: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
shaj13 committed Dec 5, 2021
1 parent 194bff9 commit bf4fd15
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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,
}
}

0 comments on commit bf4fd15

Please sign in to comment.