types

package
v0.0.0-...-91249f1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseInput

func ParseInput(r *http.Request, in *Input) (ok bool, err string)

ParseInput fills out a input struct from an http request. Returns ok if it succeeded; otherwise the string contains an error message.

func ValidateKey

func ValidateKey(next func(Input, *Response)) func(Input, *Response)

ValidateKey catches invalid keys and returns an invalid request. If the key is valid, the handler passes through.

func WrapHTTP

func WrapHTTP(next func(Input, *Response)) http.HandlerFunc

WrapHTTP wraps an method that processes Inputs and writes a Response as an http handler.

Types

type Entry

type Entry struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

An Entry is a key value pair.

type GossipResponse

type GossipResponse struct {
	Imported bool `json:"imported"`
}

type IncrementInput

type IncrementInput struct {
	Origin string `json:"origin"`
}

type Input

type Input struct {
	Entry `json:",inline"`

	// A View and StorageState is only used for view change requests.
	View         `json:",inline"`
	StorageState []store.Entry `json:"state"`

	// Context the request thinks is current
	CausalCtx clock.VectorClock `json:"causal-context"`
}

Input stores arguments to each api request

type Response

type Response struct {
	// The status code is not marshalled to JSON. The wrapper function uses this
	// to write the HTTP response body. Defaults to 200.
	Status int `json:"-"`

	// Standard information for key value storing
	Message  string `json:"message,omitempty"`
	Value    string `json:"value,omitempty"`
	Error    string `json:"error,omitempty"`
	Exists   *bool  `json:"doesExist,omitempty"`
	Replaced *bool  `json:"replaced,omitempty"`

	// Info about the state of shards
	Shards   interface{} `json:"shards,omitempty"`
	KeyCount *int        `json:"key-count,omitempty"`
	ShardId  *int        `json:"shard-id,omitempty"`
	Replicas []string    `json:"replicas,omitempty"`

	// Potential forwarding metadata
	Address string `json:"address,omitempty"`

	// Context for causal consistency
	CausalCtx clock.VectorClock `json:"causal-context"`

	// Internal view change data
	StorageState []store.Entry `json:"state,omitempty"`
}

func (*Response) Serve

func (result *Response) Serve(w http.ResponseWriter, r *http.Request)

Serve writes a response struct to an http response.

type Shard

type Shard struct {
	Id       int      `json:"shard-id"`
	Replicas []string `json:"replicas,omitempty"`
	KeyCount int      `json:"key-count"`
}

type View

type View struct {
	Members    []string `json:"view"`
	ReplFactor int      `json:"repl-factor"`
}

Jump to

Keyboard shortcuts

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