Documentation
¶
Index ¶
- Constants
- Variables
- func EndpointFromEnv() string
- func ScrollBatchSearch(ctx context.Context, client BatchSearchScroller, b Bucket, q []BatchSearch, ...) error
- func ScrollIndex(ctx context.Context, client IndexScroller, b Bucket, q ReadIndexQuery, ...) error
- type BatchInsertItem
- type BatchSearch
- type BatchSearchResult
- type BatchSearchResultHandler
- type BatchSearchScroller
- type Bucket
- type BulkGetItem
- type CausalityToken
- type Client
- func (c *Client) Clone(opts ...ClientOption) *Client
- func (c *Client) Close()
- func (c *Client) DeleteItem(ctx context.Context, b Bucket, pk string, sk string, ct CausalityToken) error
- func (c *Client) InsertBatch(ctx context.Context, b Bucket, items []BatchInsertItem) error
- func (c *Client) InsertItem(ctx context.Context, b Bucket, pk string, sk string, ct CausalityToken, ...) error
- func (c *Client) PollItem(ctx context.Context, b Bucket, pk string, sk string, ct CausalityToken, ...) (Item, CausalityToken, error)
- func (c *Client) PollRange(ctx context.Context, b Bucket, pk string, q PollRangeQuery, ...) (*PollRangeResponse, error)
- func (c *Client) ReadBatch(ctx context.Context, b Bucket, q []BatchSearch) ([]*BatchSearchResult, error)
- func (c *Client) ReadIndex(ctx context.Context, b Bucket, q ReadIndexQuery) (*ReadIndexResponse, error)
- func (c *Client) ReadItemMulti(ctx context.Context, b Bucket, pk string, sk string) ([]Item, CausalityToken, error)
- func (c *Client) ReadItemSingle(ctx context.Context, b Bucket, pk string, sk string) (Item, CausalityToken, error)
- type ClientOption
- type IndexScroller
- type Item
- type ItemKey
- type Key
- type PollRangeQuery
- type PollRangeResponse
- type ReadIndexQuery
- type ReadIndexResponse
- type ReadIndexResponseHandler
- type ReadIndexResponsePartitionKey
- type RequestMiddleware
- type SearchResultItem
Examples ¶
Constants ¶
View Source
const CausalityTokenHeader = "X-Garage-Causality-Token"
View Source
const EnvVarEndpoint = "K2V_ENDPOINT"
View Source
const EnvVarKeyID = "K2V_KEY_ID"
View Source
const EnvVarKeySecret = "K2V_KEY_SECRET"
Variables ¶
View Source
var ConcurrentItemsErr = errors.New("item has multiple concurrent values")
View Source
var NoSuchItemErr = errors.New("item does not exist")
View Source
var NotModifiedTimeoutErr = errors.New("not modified within timeout")
View Source
var StopScroll = errors.New("scroll canceled")
View Source
var TombstoneItemErr = errors.New("item is a tombstone")
Functions ¶
func EndpointFromEnv ¶
func EndpointFromEnv() string
func ScrollBatchSearch ¶ added in v0.1.1
func ScrollBatchSearch(ctx context.Context, client BatchSearchScroller, b Bucket, q []BatchSearch, fn BatchSearchResultHandler) error
func ScrollIndex ¶ added in v0.1.1
func ScrollIndex(ctx context.Context, client IndexScroller, b Bucket, q ReadIndexQuery, fn ReadIndexResponseHandler) error
ScrollIndex calls the ReadIndex API serially, invoking the provided function for each response (batch) until there are no more results.
Example ¶
ctx := context.Background() client := k2v.NewClient(k2v.EndpointFromEnv(), k2v.KeyFromEnv()) defer client.Close() const bucket = "k2v-test" pkPrefix := randomPk() for i := range 5 { _ = client.InsertItem(ctx, bucket, pkPrefix+"-"+strconv.Itoa(i), randomSk(), "", []byte("hello")) } var responses []*k2v.ReadIndexResponse _ = k2v.ScrollIndex(ctx, client, bucket, k2v.ReadIndexQuery{Prefix: pkPrefix, Limit: 25}, func(resp *k2v.ReadIndexResponse) error { responses = append(responses, resp) return nil }) fmt.Println(len(responses[0].PartitionKeys))
Output: 5
Types ¶
type BatchInsertItem ¶
type BatchSearch ¶ added in v0.1.1
type BatchSearch struct { PartitionKey string `json:"partitionKey"` // Prefix restricts listing to partition keys that start with this value. Prefix string `json:"prefix,omitempty"` // Start is the first partition key to list, in lexicographical order. Start string `json:"start,omitempty"` // End is the last partition key to list (excluded). End string `json:"end,omitempty"` // Limit for maximum number of partition keys to list. Limit int `json:"limit,omitempty"` // Reverse iterates in reverse lexicographical order. Reverse bool `json:"reverse,omitempty"` // SingleItem determines whether to return only the item with sort key start. SingleItem bool `json:"singleItem,omitempty"` // ConflictsOnly determines whether to return only items that have several concurrent values. ConflictsOnly bool `json:"conflictsOnly,omitempty"` // Tombstones determines whether or not to return tombstone lines to indicate the presence of old deleted items. Tombstones bool `json:"tombstones,omitempty"` }
type BatchSearchResult ¶
type BatchSearchResult struct { PartitionKey string `json:"partitionKey"` Prefix *string `json:"prefix"` Start *string `json:"start"` End *string `json:"end"` Limit *int `json:"limit"` Reverse bool `json:"reverse"` SingleItem bool `json:"singleItem"` ConflictsOnly bool `json:"conflictsOnly"` Tombstones bool `json:"tombstones"` Items []SearchResultItem `json:"items"` More bool `json:"more"` NextStart *string `json:"nextStart"` }
type BatchSearchResultHandler ¶ added in v0.1.1
type BatchSearchResultHandler func(result *BatchSearchResult) error
type BatchSearchScroller ¶ added in v0.1.1
type BatchSearchScroller interface {
ReadBatch(ctx context.Context, b Bucket, q []BatchSearch) ([]*BatchSearchResult, error)
}
type BulkGetItem ¶
type BulkGetItem struct { PartitionKey string SortKey string CausalityToken CausalityToken Values []Item }
type CausalityToken ¶
type CausalityToken string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Clone ¶
func (c *Client) Clone(opts ...ClientOption) *Client
func (*Client) DeleteItem ¶
func (*Client) InsertBatch ¶
func (*Client) InsertItem ¶
func (*Client) PollRange ¶ added in v0.1.1
func (c *Client) PollRange(ctx context.Context, b Bucket, pk string, q PollRangeQuery, timeout time.Duration) (*PollRangeResponse, error)
func (*Client) ReadBatch ¶
func (c *Client) ReadBatch(ctx context.Context, b Bucket, q []BatchSearch) ([]*BatchSearchResult, error)
func (*Client) ReadIndex ¶
func (c *Client) ReadIndex(ctx context.Context, b Bucket, q ReadIndexQuery) (*ReadIndexResponse, error)
func (*Client) ReadItemMulti ¶
type ClientOption ¶
type ClientOption func(*Client)
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
func WithRequestMiddleware ¶
func WithRequestMiddleware(middleware ...RequestMiddleware) ClientOption
type IndexScroller ¶ added in v0.1.1
type IndexScroller interface {
ReadIndex(ctx context.Context, b Bucket, q ReadIndexQuery) (*ReadIndexResponse, error)
}
type PollRangeQuery ¶ added in v0.1.1
type PollRangeQuery struct { // Prefix restricts items to poll to those whose sort keys start with this prefix. Prefix string `json:"prefix,omitempty"` // Start is the sort key of the first item to poll. Start string `json:"start,omitempty"` // End is the sort key of the last item to poll (excluded). End string `json:"end,omitempty"` // SeenMarker is an opaque string returned by a previous PollRange call, that represents items already seen. SeenMarker string `json:"seenMarker,omitempty"` }
type PollRangeResponse ¶ added in v0.1.1
type PollRangeResponse struct { SeenMarker string `json:"seenMarker"` Items []SearchResultItem `json:"items"` }
type ReadIndexQuery ¶
type ReadIndexQuery struct { // Prefix restricts listing to partition keys that start with this value. Prefix string // Start is the first partition key to list, in lexicographical order. Start string // End is the last partition key to list (excluded). End string // Limit for maximum number of partition keys to list. Limit int // Reverse iterates in reverse lexicographical order. Reverse bool }
type ReadIndexResponse ¶
type ReadIndexResponse struct { Prefix *string `json:"prefix"` Start *string `json:"start"` End *string `json:"end"` Limit *int `json:"limit"` Reverse bool `json:"reverse"` PartitionKeys []ReadIndexResponsePartitionKey `json:"partitionKeys"` More bool `json:"more"` NextStart *string `json:"nextStart"` }
type ReadIndexResponseHandler ¶ added in v0.1.1
type ReadIndexResponseHandler func(resp *ReadIndexResponse) error
ReadIndexResponseHandler is invoked for each batch of index read results.
If an error is returned, scrolling is halted and the error is propagated. The sentinel value StopScroll can be returned to end iteration early without propagating an error.
type RequestMiddleware ¶
type SearchResultItem ¶
Click to show internal directories.
Click to hide internal directories.