Documentation ¶
Overview ¶
Package rafthttp provides a HTTP/JSON-based raft transport.
Example ¶
package main import ( "net/http" "github.com/robustirc/rafthttp" ) func main() { transport := rafthttp.NewHTTPTransport( "test.example.net:8080", http.DefaultClient, nil, "") http.Handle("/raft/", transport) go http.ListenAndServe(":8080", nil) // Initialize raft… }
Output:
Index ¶
- type Doer
- type HTTPTransport
- func (t *HTTPTransport) AppendEntries(_ raft.ServerID, target raft.ServerAddress, args *raft.AppendEntriesRequest, ...) error
- func (t *HTTPTransport) AppendEntriesPipeline(_ raft.ServerID, target raft.ServerAddress) (raft.AppendPipeline, error)
- func (t *HTTPTransport) Consumer() <-chan raft.RPC
- func (t *HTTPTransport) DecodePeer(b []byte) raft.ServerAddress
- func (t *HTTPTransport) EncodePeer(_ raft.ServerID, a raft.ServerAddress) []byte
- func (t *HTTPTransport) InstallSnapshot(_ raft.ServerID, target raft.ServerAddress, args *raft.InstallSnapshotRequest, ...) error
- func (t *HTTPTransport) LocalAddr() raft.ServerAddress
- func (t *HTTPTransport) RequestVote(_ raft.ServerID, target raft.ServerAddress, args *raft.RequestVoteRequest, ...) error
- func (t *HTTPTransport) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (t *HTTPTransport) SetHeartbeatHandler(cb func(rpc raft.RPC))
- func (t *HTTPTransport) TimeoutNow(_ raft.ServerID, target raft.ServerAddress, args *raft.TimeoutNowRequest, ...) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Doer ¶
Doer provides the Do() method, as found in net/http.Client.
Using this interface instead of net/http.Client directly is useful so that users of the HTTPTransport can wrap requests to, for example, call req.SetBasicAuth.
type HTTPTransport ¶
type HTTPTransport struct {
// contains filtered or unexported fields
}
HTTPTransport provides a HTTP-based transport that can be used to communicate with Raft on remote machines. It is convenient to use if your application is an HTTP server already and you do not want to use multiple different transports (if not, you can use raft.NetworkTransport).
func NewHTTPTransport ¶
func NewHTTPTransport(addr raft.ServerAddress, client Doer, logger *log.Logger, urlFmt string) *HTTPTransport
NewHTTPTransport creates a new HTTP transport on the given addr.
client must implement the Doer interface, but you can use e.g. net/http.DefaultClient if you do not need to wrap the Do() method.
logger defaults to log.New(os.Stderr, "", log.LstdFlags) if nil.
urlFmt defaults to "https://%v/raft/" and will be used in fmt.Sprintf(urlFmt+"/method", target) where method is the raft RPC method (e.g. appendEntries).
func (*HTTPTransport) AppendEntries ¶
func (t *HTTPTransport) AppendEntries(_ raft.ServerID, target raft.ServerAddress, args *raft.AppendEntriesRequest, resp *raft.AppendEntriesResponse) error
AppendEntries implements the raft.Transport interface.
func (*HTTPTransport) AppendEntriesPipeline ¶
func (t *HTTPTransport) AppendEntriesPipeline(_ raft.ServerID, target raft.ServerAddress) (raft.AppendPipeline, error)
AppendEntriesPipeline implements the raft.Transport interface.
func (*HTTPTransport) Consumer ¶
func (t *HTTPTransport) Consumer() <-chan raft.RPC
Consumer implements the raft.Transport interface.
func (*HTTPTransport) DecodePeer ¶
func (t *HTTPTransport) DecodePeer(b []byte) raft.ServerAddress
DecodePeer implements the raft.Transport interface.
func (*HTTPTransport) EncodePeer ¶
func (t *HTTPTransport) EncodePeer(_ raft.ServerID, a raft.ServerAddress) []byte
EncodePeer implements the raft.Transport interface.
func (*HTTPTransport) InstallSnapshot ¶
func (t *HTTPTransport) InstallSnapshot(_ raft.ServerID, target raft.ServerAddress, args *raft.InstallSnapshotRequest, resp *raft.InstallSnapshotResponse, data io.Reader) error
InstallSnapshot implements the raft.Transport interface.
func (*HTTPTransport) LocalAddr ¶
func (t *HTTPTransport) LocalAddr() raft.ServerAddress
LocalAddr implements the raft.Transport interface.
func (*HTTPTransport) RequestVote ¶
func (t *HTTPTransport) RequestVote(_ raft.ServerID, target raft.ServerAddress, args *raft.RequestVoteRequest, resp *raft.RequestVoteResponse) error
RequestVote implements the raft.Transport interface.
func (*HTTPTransport) ServeHTTP ¶
func (t *HTTPTransport) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeHTTP implements the net/http.Handler interface, so that you can use
http.Handle("/raft/", transport)
func (*HTTPTransport) SetHeartbeatHandler ¶
func (t *HTTPTransport) SetHeartbeatHandler(cb func(rpc raft.RPC))
SetHeartbeatHandler implements the raft.Transport interface.
func (*HTTPTransport) TimeoutNow ¶
func (t *HTTPTransport) TimeoutNow(_ raft.ServerID, target raft.ServerAddress, args *raft.TimeoutNowRequest, resp *raft.TimeoutNowResponse) error
TimeoutNow implements the raft.Transport interface.