rest

package
v0.0.0-...-a1c4c83 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// API is the root of the REST API.
	API = "/api"

	// APIV1 is the versiond endpoint, all endpoints should be postfixed to this one.
	APIV1 = API + "/v1"

	// APIV1AppendEntries is the endpoint for the 'AppendEntries' operation.
	APIV1AppendEntries = APIV1 + "/append-entries"

	// APIV1RequestVote is the endpoint for the 'RequestVote' operation.
	APIV1RequestVote = APIV1 + "/request-vote"

	// APIV1KV is the endpoint for performing key value operations.
	APIV1KV = APIV1 + "/key-value"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements the Raft client interface allowing intra-cluster communication via a REST API.

func NewClient

func NewClient(url *url.URL) *Client

NewClient returns a new client which will communicate with the node a the given address.

func (*Client) Address

func (c *Client) Address() *url.URL

Address returns the address of the remote node.

func (*Client) AppendEntries

func (c *Client) AppendEntries(ctx context.Context, input raft.AppendEntriesInput) (raft.AppendEntriesOutput, error)

AppendEntries dispatches an append entries request to the remote node.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, input raft.DeleteInput) error

Delete dispatches a 'Delete' request to the remote node.

func (*Client) Get

func (c *Client) Get(ctx context.Context, input raft.GetInput) (raft.GetOutput, error)

Get dispatches a 'Get' request to the remote node.

func (*Client) RequestVote

func (c *Client) RequestVote(ctx context.Context, input raft.RequestVoteInput) (raft.RequestVoteOutput, error)

RequestVote dispatches a request vote request to the remote node.

func (*Client) Set

func (c *Client) Set(ctx context.Context, input raft.SetInput) error

Set dispatches a 'Set' request to the remote node.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements the Raft client interface allowing intra-cluster communication via a REST API.

func NewServer

func NewServer(consensus raft.Protocol) *Server

NewServer returns a server which hosts all the required endpoints to allow intra-cluster communication.

func (*Server) AppendEntries

func (s *Server) AppendEntries(writer http.ResponseWriter, req *http.Request)

AppendEntries handles an 'AppendEntries' request.

func (*Server) Delete

func (s *Server) Delete(writer http.ResponseWriter, req *http.Request)

Delete a key/value pair.

func (*Server) Get

func (s *Server) Get(writer http.ResponseWriter, req *http.Request)

Get returns a key/value pair.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the server on the given address/port.

func (*Server) RequestVote

func (s *Server) RequestVote(writer http.ResponseWriter, req *http.Request)

RequestVote handles a 'RequestVote' request.

func (*Server) Set

func (s *Server) Set(writer http.ResponseWriter, req *http.Request)

Set a key/value pair.

type UnexpectedStatusCodeError

type UnexpectedStatusCodeError struct {
	Status  int
	Method  string
	Address string
	Body    []byte
}

UnexpectedStatusCodeError is returned if a REST request resulted in a non-2xx status code.

func (UnexpectedStatusCodeError) Error

Error implements the 'error' interface and returns a useful error message indicating what request failed.

Jump to

Keyboard shortcuts

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