rafthttp

package module
v0.0.0-...-5ca12e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2022 License: BSD-3-Clause Imports: 13 Imported by: 1

README

RobustIRC is in semi-private beta. We currently offer no help, no stability guarantees, no instructions. Please come back at a later point in time, once we actually published something :).

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

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

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

InstallSnapshot implements the raft.Transport interface.

func (*HTTPTransport) LocalAddr

func (t *HTTPTransport) LocalAddr() raft.ServerAddress

LocalAddr implements the raft.Transport interface.

func (*HTTPTransport) RequestVote

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

TimeoutNow implements the raft.Transport interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL