gorc

package
v0.0.0-...-711f10a Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: GPL-2.0, Apache-2.0 Imports: 15 Imported by: 0

README

gorc

A golang client for Orchestrate.io

Supports go 1.1 or later

Go Style Documentation: http://godoc.org/github.com/orchestrate-io/gorc

Usage examples

    // Import the client
    import "github.com/orchestrate-io/gorc"

    // Create a client
    c := gorc.NewClient("Your API Key")

    // Get a value
    result, _ := c.Get("collection", "key")

    // Marshall value into a map
    valueMap := make(map[string]interface{})
    result.Value(&valueMap)

    // Marshall value into a domain type
    domainObject := DomainObject{}
    result.Value(&domainObject)

    // Put a serialized value
    c.PutRaw("collection", "key", strings.NewReader("Some JSON"))

    // Put a interface{} type
    group := Group{Name: "name", Founded: 1990}
    c.Put("collection", "key", group)

    // Search
    results, _ := c.Search("collection", "A Lucene Query", 100, 0)

    // Marshall (search/event/graph) results into an array of domain objects
    var values []DomainObject{} = make([]DomainObject{}, len(results.Results))
    for i, result := range results.Results {
        result.Value(&values[i])
    }

    // Get next page of results
    if results.HasNext() {
        results, err := c.SearchGetNext(results)
    }

    // Get Events
    events, _ := c.GetEvents("collection", "key", "kind")

    // Put Events
    c.PutEvent("collection", "key", "kind", domainObject)
    c.PutEventRaw("collection", "key", "kind", strings.NewReader(serializedJson))

    // Get Relations
    relations, _ := c.GetRelations("collection", "key", []string{"kind", "kind"})

    // Put Relation
    c.PutRelation("sourceCollection", "sourceKey", "kind", "sinkCollection", "sinkKey")

    // Get a value at a particular ref
    valueAtRef := c.GetRef("collection", "key", "ref")

    // List the last 10 values of a collection-key pair
    valueHistory := c.ListRefs("collection", "key", 10, true)

Documentation

Overview

A client for use with Orchestrate.io: http://orchestrate.io/

Orchestrate unifies multiple databases through one simple REST API. Orchestrate runs as a service and supports queries like full-text search, events, graph, and key/value.

You can sign up for an Orchestrate account here: http://dashboard.orchestrate.io

Index

Constants

This section is empty.

Variables

View Source
var (
	// This is the default hostname that will be queried for API calls.
	DefaultAPIHost = "api.orchestrate.io"

	// The default timeout that will be used for connections. This is used
	// with the default Transport to establish how long a connection attempt
	// can take. This is not the data transfer timeout. Changing this will
	// impact all new connections made with the default transport.
	DefaultDialTimeout = 3 * time.Second

	// This is the default http.Transport that will be associated with new
	// clients. If overwritten then only new clients will be impacted, old
	// clients will continue to use the pre-existing transport.
	DefaultTransport *http.Transport = &http.Transport{

		MaxIdleConnsPerHost: 4,

		ResponseHeaderTimeout: 3 * time.Second,

		Dial: func(network, addr string) (net.Conn, error) {
			return net.DialTimeout(network, addr, DefaultDialTimeout)
		},
	}
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// This is the host name that will be used in client queries. By default
	// this will be set to DefaultAPIHost, and if this is left empty
	// then that default will be used as well.
	APIHost string

	// This is the HTTP client that will be used to perform HTTP queries
	// against Orchestrate.
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

An Orchestrate Client object.

func NewClient

func NewClient(authToken string) *Client

Returns a new Client object that will use the given authToken for authorization against Orchestrate. This token can be obtained at http://dashboard.orchestrate.io

func NewClientWithTransport

func NewClientWithTransport(
	deprecated_authToken string, deprecated_transport *http.Transport,
) *Client

This function is deprecated. Please just set the HTTPClient field on the client object manually.

func (*Client) Delete

func (c *Client) Delete(collection, key string) error

Delete the value held at a collection-key pair.

func (*Client) DeleteCollection

func (c *Client) DeleteCollection(collection string) error

Delete a collection.

func (*Client) DeleteIfUnmodified

func (c *Client) DeleteIfUnmodified(path *Path) error

Delete the value held at a collection-key par if the path's ref value is the latest.

func (*Client) DeleteRelation

func (c *Client) DeleteRelation(sourceCollection string, sourceKey string, kind string, sinkCollection string, sinkKey string) error

Create a relationship of a specified type between two collection-keys.

func (*Client) Get

func (c *Client) Get(collection, key string) (*KVResult, error)

Get a collection-key pair's value.

func (*Client) GetEvents

func (c *Client) GetEvents(collection, key, kind string) (*EventResults, error)

Get latest events of a particular type from specified collection-key pair.

func (*Client) GetEventsInRange

func (c *Client) GetEventsInRange(collection, key, kind string, start int64, end int64) (*EventResults, error)

Get all events of a particular type from specified collection-key pair in a range.

func (*Client) GetEventsInRangeWithLimit

func (c *Client) GetEventsInRangeWithLimit(collection, key, kind string, start, end, limit int64) (*EventResults, error)

Get all events of a particular type from a specified collection-key in a range with a limit

func (*Client) GetPath

func (c *Client) GetPath(path *Path) (*KVResult, error)

Get the value at a path.

func (*Client) GetRef

func (c *Client) GetRef(collection, key, ref string) (*KVResult, error)

Get a collection-key pair's value at a specific ref.

func (*Client) GetRelations

func (c *Client) GetRelations(collection, key string, hops []string) (*GraphResults, error)

Get all related key/value objects by collection-key and a list of relations.

func (*Client) List

func (c *Client) List(collection string, limit int) (*KVResults, error)

List the values in a collection in key order with the specified page size.

func (*Client) ListAfter

func (c *Client) ListAfter(collection, after string, limit int) (*KVResults, error)

List the values in a collection in key order with the specified page size that come after the specified key.

func (*Client) ListGetNext

func (c *Client) ListGetNext(results *KVResults) (*KVResults, error)

Get the page of key/value list results that follow that provided set.

func (*Client) ListRange

func (c *Client) ListRange(collection, start, end string, limit int) (*KVResults, error)

List the values in a collection within a given range of keys, starting with the specified key and stopping at the end key

func (*Client) ListRefs

func (c *Client) ListRefs(collection, key string, limit int, values bool) (*RefResults, error)

List the refs of a value in time order with the specified page size optionally retrieving values.

func (*Client) ListRefsFromOffset

func (c *Client) ListRefsFromOffset(collection, key string, limit int, values bool, offset int) (*RefResults, error)

List the refs of a value in time order with the specified page size optionally retrieving values starting at the specified offset.

func (*Client) ListRefsGetNext

func (c *Client) ListRefsGetNext(results *RefResults) (*RefResults, error)

Get the page of ref list results that follow the provided set.

func (*Client) ListStart

func (c *Client) ListStart(collection, start string, limit int) (*KVResults, error)

List the values in a collection in key order with the specified page size starting with the specified key.

func (*Client) Ping

func (c *Client) Ping() error

Check that Orchestrate is reachable.

func (*Client) Purge

func (c *Client) Purge(collection, key string) error

Delete the current and all previous values from a collection-key pair.

func (*Client) Put

func (c *Client) Put(collection string, key string, value interface{}) (*Path, error)

Store a value to a collection-key pair.

func (*Client) PutEvent

func (c *Client) PutEvent(collection, key, kind string, value interface{}) error

Put an event of the specified type to provided collection-key pair.

func (*Client) PutEventRaw

func (c *Client) PutEventRaw(collection, key, kind string, value io.Reader) error

Put an event of the specified type to provided collection-key pair.

func (*Client) PutEventWithTime

func (c *Client) PutEventWithTime(collection, key, kind string, time int64, value interface{}) error

Put an event of the specified type to provided collection-key pair and time.

func (*Client) PutEventWithTimeRaw

func (c *Client) PutEventWithTimeRaw(collection, key, kind string, time int64, value io.Reader) error

Put an event of the specified type to provided collection-key pair and time.

func (*Client) PutIfAbsent

func (c *Client) PutIfAbsent(collection, key string, value interface{}) (*Path, error)

Store a value to a collection-key pair if it doesn't already hold a value.

func (*Client) PutIfAbsentRaw

func (c *Client) PutIfAbsentRaw(collection, key string, value io.Reader) (*Path, error)

Store a value to a collection-key pair if it doesn't already hold a value.

func (*Client) PutIfUnmodified

func (c *Client) PutIfUnmodified(path *Path, value interface{}) (*Path, error)

Store a value to a collection-key pair if the path's ref value is the latest.

func (*Client) PutIfUnmodifiedRaw

func (c *Client) PutIfUnmodifiedRaw(path *Path, value io.Reader) (*Path, error)

Store a value to a collection-key pair if the path's ref value is the latest.

func (*Client) PutRaw

func (c *Client) PutRaw(collection string, key string, value io.Reader) (*Path, error)

Store a value to a collection-key pair.

func (*Client) PutRelation

func (c *Client) PutRelation(sourceCollection, sourceKey, kind, sinkCollection, sinkKey string) error

Create a relationship of a specified type between two collection-keys.

func (*Client) Search

func (c *Client) Search(
	collection, query string, limit, offset int,
) (*SearchResults, error)

Search a collection with a Lucene Query Parser Syntax Query (http://lucene.apache.org/core/4_5_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Overview) and with a specified size limit and offset.

func (*Client) SearchGetNext

func (c *Client) SearchGetNext(results *SearchResults) (*SearchResults, error)

Get the page of search results that follow that provided set.

func (*Client) SearchGetPrev

func (c *Client) SearchGetPrev(results *SearchResults) (*SearchResults, error)

Get the page of search results that precede that provided set.

func (*Client) SearchSorted

func (c *Client) SearchSorted(
	collection, query, sortBy string, limit, offset int,
) (*SearchResults, error)

Like Search() except this sorts the search results.

sortBy is a dot joined field list followed by either "asc" or "desc". for example: "value.field1:asc" would sort all of the results, ascending by the value in "field1" in each document.

TODO: Add a link to the blog post documenting this.

type Event

type Event struct {
	Ordinal   uint64          `json:"ordinal"`
	Timestamp uint64          `json:"timestamp"`
	RawValue  json.RawMessage `json:"value"`
}

An individual event.

func (*Event) Value

func (r *Event) Value(value interface{}) error

Marshall the value of an event into the provided object.

type EventResults

type EventResults struct {
	Count   uint64  `json:"count"`
	Results []Event `json:"results"`
}

Holds results returned from an Events query.

type GraphResult

type GraphResult struct {
	Path     Path            `json:"path"`
	RawValue json.RawMessage `json:"value"`
}

An individual graph result.

func (*GraphResult) Value

func (r *GraphResult) Value(value interface{}) error

Marshall the value of a GraphResult into the provided object.

type GraphResults

type GraphResults struct {
	Count   uint64        `json:"count"`
	Results []GraphResult `json:"results"`
}

Holds results returned from a Graph query.

type KVResult

type KVResult struct {
	Path     Path            `json:"path"`
	RawValue json.RawMessage `json:"value"`
}

An individual Key/Value result.

func (*KVResult) Value

func (r *KVResult) Value(value interface{}) error

Marshall the value of a KVResult into the provided object.

type KVResults

type KVResults struct {
	Count   uint64     `json:"count"`
	Results []KVResult `json:"results"`
	Next    string     `json:"next,omitempty"`
}

Holds results returned from a KV list query.

func (*KVResults) HasNext

func (r *KVResults) HasNext() bool

Check if there is a subsequent page of key/value list results.

type OrchestrateError

type OrchestrateError struct {
	// The status string returned from the HTTP call.
	Status string `json:"-"`

	// The status, as an integer, returned from the HTTP call.
	StatusCode int `json:"-"`

	// The Orchestrate specific message representing the error.
	Message string `json:"message"`
}

An implementation of 'error' that exposes all the orchestrate specific error details.

func (OrchestrateError) Error

func (e OrchestrateError) Error() string

Convert the error to a meaningful string.

type Path

type Path struct {
	Collection string `json:"collection"`
	Key        string `json:"key"`
	Ref        string `json:"ref"`
	Tombstone  bool   `json:"tombstone,omitempty"`
}

A representation of a Key/Value object's path within Orchestrate.

type RefResult

type RefResult struct {
	Path     Path            `json:"path"`
	RawValue json.RawMessage `json:"value,omitempty"`
	RefTime  uint64          `json:"reftime"`
}

An individual ref result.

func (*RefResult) IsDeleted

func (r *RefResult) IsDeleted() bool

Determines if the given ref represents a deletion.

func (*RefResult) Value

func (r *RefResult) Value(value interface{}) error

Marshall the value of a RefResult into the provided object.

type RefResults

type RefResults struct {
	Count   uint64      `json:"count"`
	Results []RefResult `json:"results"`
	Next    string      `json:"next,omitempty"`
}

Holds results returned from a ref list.

func (*RefResults) HasNext

func (r *RefResults) HasNext() bool

Check if there is a subsequent page of ref list results.

type SearchResult

type SearchResult struct {
	Path     Path            `json:"path"`
	Score    float64         `json:"score"`
	Distance float64         `json:"distance"`
	RawValue json.RawMessage `json:"value"`
}

An individual search result.

func (*SearchResult) Value

func (r *SearchResult) Value(value interface{}) error

Marshall the value of a SearchResult into the provided object.

type SearchResults

type SearchResults struct {
	Count      uint64         `json:"count"`
	TotalCount uint64         `json:"total_count"`
	Results    []SearchResult `json:"results"`
	Next       string         `json:"next,omitempty"`
	Prev       string         `json:"prev,omitempty"`
}

Holds results returned from a Search query.

func (*SearchResults) HasNext

func (r *SearchResults) HasNext() bool

Check if there is a subsequent page of search results.

func (*SearchResults) HasPrev

func (r *SearchResults) HasPrev() bool

Check if there is a previous page of search results.

Jump to

Keyboard shortcuts

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