Documentation ¶
Overview ¶
Package httpapi implements a simple API as a tech demo. Values must be URL-encodable strings, and the only supported change function is compare-and-swap.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcceptorClient ¶
type AcceptorClient struct { // URL of the remote acceptor HTTP API. Required. URL *url.URL // HTTPClient used to make remote HTTP requests. Optional. // By default, http.DefaultClient is used. HTTPClient interface { Do(*http.Request) (*http.Response, error) } }
AcceptorClient implements qkstore.Acceptor by making HTTP requests to a remote AcceptorServer.
func (AcceptorClient) Accept ¶
func (ac AcceptorClient) Accept(ctx context.Context, key string, b qkstore.Ballot, value []byte) error
Accept implements qkstore.Acceptor by making an HTTP request to the remote acceptor API.
func (AcceptorClient) Address ¶
func (ac AcceptorClient) Address() string
Address implements qkstore.Acceptor, returning the wrapped URL.
type AcceptorServer ¶
AcceptorServer wraps a qkstore.Acceptor and provides a basic HTTP API. It's an internal API; it should only be called by proposers, via the AcceptorClient.
POST /prepare/{key} Prepare request for the given key. Expects and returns "X-Caspaxos-Ballot: Counter/ID" header. Returns 412 Precondition Failed on protocol error. POST /accept/{key}?value=VALUE Accept request for the given key and value. Value may be empty. Expects "X-Caspaxos-Ballot: Counter/ID" header. Returns 406 Not Acceptable on protocol error.
func NewAcceptorServer ¶
func NewAcceptorServer(acceptor qkstore.Acceptor, logger log.Logger) AcceptorServer
NewAcceptorServer returns an AcceptorServer wrapping the provided acceptor. The AcceptorServer is an http.Handler and can ServeHTTP.
type ProposerServer ¶
ProposerServer wraps a qkstore.Proposer and provides a basic HTTP API. Note that this is an artificially restricted API. The protocol itself is much more expressive, this is mostly meant as a tech demo.
GET /{key} Returns the current version and value for key. Returns 404 Not Found if the key doesn't exist. POST /{key}?version={version}&value={value} Performs a compare-and-swap, writing value to key. Version should be the current version of the key. Returns 412 Precondition Failed on version error. DELETE /{key}?version={version} Deletes the key, if the version matches. Returns 404 Not Found if the key doesn't exist. Returns 412 Precondition Failed on version error.
func NewProposerServer ¶
func NewProposerServer(proposer qkstore.Proposer, logger log.Logger) ProposerServer
NewProposerServer returns an ProposerServer wrapping the provided proposer. The ProposerServer is an http.Handler and can ServeHTTP.