t38c

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 10 Imported by: 5

README

Tile38 Client for Go

Go Documentation Go Report Card codecov license

See what Tile38 is all about.

Installation
go get github.com/xjem/t38c@latest
Basic example
package main

import (
	"fmt"

	"github.com/xjem/t38c"
)

func main() {
	tile38, err := t38c.New(t38c.Config{
		Address: "localhost:9851",
		Debug:   true, // print queries to stdout
	})
	if err != nil {
		panic(err)
	}
	defer client.Close()

	if err := client.Keys.Set("fleet", "truck1").Point(33.5123, -112.2693).Do(context.TODO()); err != nil {
		panic(err)
	}

	if err := client.Keys.Set("fleet", "truck2").Point(33.4626, -112.1695).
		Field("speed", 20). // optional
		Expiration(20).     // optional
		Do(context.TODO()); err != nil {
		panic(err)
	}

	// search 6 kilometers around a point. returns one truck.
	response, err := client.Search.Nearby("fleet", 33.462, -112.268, 6000).
		Where("speed", 0, 100).
		Match("truck*").
		Format(t38c.FormatPoints).
		Do(context.TODO())
	if err != nil {
		panic(err)
	}

	// truck1 {33.5123 -112.2693}
	fmt.Println(response.Points[0].ID, response.Points[0].Point)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FormatCount - Total object count sent in the response.
	// When LIMIT or CURSOR are provided, COUNT returns the number of results that would otherwise be sent as objects.
	// When LIMIT is not specified, COUNT totals up all items starting from provided CURSOR position
	// (or zero if a cursor is omitted). LIMIT and CURSOR options are ignored.
	FormatCount = OutputFormat(newCmd("COUNT"))
	// FormatIDs - A list of IDs belonging to the key. Will not return the objects.
	FormatIDs = OutputFormat(newCmd("IDS"))
	// FormatPoints - A list of standard latitude, longitude points.
	FormatPoints = OutputFormat(newCmd("POINTS"))
	// FormatBounds - A list of minimum bounding rectangle.
	FormatBounds = OutputFormat(newCmd("BOUNDS"))
	// FormatHashes - A list of Geohash. Requires a precision of 1 to 22.
	FormatHashes = func(precision int) OutputFormat {
		return OutputFormat(newCmd("HASHES", strconv.Itoa(precision)))
	}
)

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	SW Point `json:"sw"`
	NE Point `json:"ne"`
}

Bounds is a tile38 bounds object.

type Chan

type Chan struct {
	Name    string            `json:"name"`
	Key     string            `json:"key"`
	Command []string          `json:"command"`
	Meta    map[string]string `json:"meta"`
}

Chan represents tile38 channel.

type Channels

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

Channels struct

func (*Channels) Chans

func (ch *Channels) Chans(ctx context.Context, pattern string) ([]Chan, error)

Chans returns all Channels matching pattern.

func (*Channels) DelChan

func (ch *Channels) DelChan(ctx context.Context, name string) error

DelChan remove a specified channel.

func (*Channels) PDelChan

func (ch *Channels) PDelChan(ctx context.Context, pattern string) error

PDelChan removes all Channels that match the specified pattern.

func (*Channels) PSubscribe

func (ch *Channels) PSubscribe(ctx context.Context, handler EventHandler, pattern string) error

PSubscribe subscribes the client to the given patterns.

func (*Channels) SetChan

SetChan creates a Pub/Sub channel which points to a geofenced search. If a channel is already associated to that name, it’ll be overwritten. Once the channel is created a client can then listen for events on that channel with SUBSCRIBE or PSUBSCRIBE. If expiration less than 0, it will be ignored

func (*Channels) Subscribe

func (ch *Channels) Subscribe(ctx context.Context, handler EventHandler, Channels ...string) error

Subscribe subscribes the client to the specified Channels.

type Client

type Client struct {
	Search    *Search
	Keys      *Keys
	Webhooks  *Hooks
	Channels  *Channels
	Scripting *Scripting
	Geofence  *Geofence
	Server    *Server
	// contains filtered or unexported fields
}

Client allows you to interact with the Tile38 server.

func New

func New(cfg Config) (*Client, error)

New creates a new Tile38 client.

func NewWithExecutor

func NewWithExecutor(exec Executor, debug bool) (*Client, error)

NewWithExecutor creates a new Tile38 client with provided executor. See Executor interface for more information.

func (*Client) Close

func (client *Client) Close() error

Close closes all connections in the pool and rejects future execution calls. Blocks until all streams are closed.

NOTE: custom Executor implementation may change behavior.

func (*Client) Execute

func (client *Client) Execute(ctx context.Context, command string, args ...string) ([]byte, error)

Execute Tile38 command.

func (*Client) ExecuteStream

func (client *Client) ExecuteStream(ctx context.Context, handler func([]byte) error, command string, args ...string) error

ExecuteStream used for Tile38 commands with streaming response.

func (*Client) HealthZ added in v0.9.6

func (client *Client) HealthZ(ctx context.Context) error

Health Check

func (*Client) Ping

func (client *Client) Ping(ctx context.Context) error

Ping the server.

type Config added in v0.11.0

type Config struct {
	// Tile38 server address.
	//
	// Example: localhost:9851
	Address string

	// Enables debug logging.
	// Executed queries will be printed to stdout.
	Debug bool

	// Allows to perform password authorization.
	Password *string

	// ConnectionPoolSize sets number of connections in the pool.
	// Defaults to 4.
	ConnectionPoolSize int
}

Config is a t38c client config.

type DetectAction

type DetectAction string

DetectAction ...

const (
	// Inside is when an object is inside the specified area.
	Inside DetectAction = "inside"
	// Outside is when an object is outside the specified area.
	Outside DetectAction = "outside"
	// Enter is when an object that was not previously in the fence has entered the area.
	Enter DetectAction = "enter"
	// Exit is when an object that was previously in the fence has exited the area.
	Exit DetectAction = "exit"
	// Cross is when an object that was not previously in the fence has entered and exited the area.
	Cross DetectAction = "cross"
)

type EventHandler added in v0.11.0

type EventHandler interface {
	// HandleEvent handles tile38 event.
	HandleEvent(event *GeofenceEvent) error
}

EventHandler handles tile38 events.

type EventHandlerFunc added in v0.11.0

type EventHandlerFunc func(event *GeofenceEvent) error

EventHandlerFunc is an adapter to allow the use of ordinary functions as tile38 event handlers.

func (EventHandlerFunc) HandleEvent added in v0.11.0

func (e EventHandlerFunc) HandleEvent(event *GeofenceEvent) error

HandleEvent handles tile38 event.

type Executor

type Executor interface {
	Execute(ctx context.Context, command string, args ...string) ([]byte, error)
	ExecuteStream(ctx context.Context, handler func([]byte) error, command string, args ...string) error
	Close() error
}

Executor represents Tile38 connection. Communication should be in JSON format only.

type FSetQueryBuilder

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

FSetQueryBuilder struct

func (FSetQueryBuilder) Do

func (query FSetQueryBuilder) Do(ctx context.Context) error

Do cmd

func (FSetQueryBuilder) Field

func (query FSetQueryBuilder) Field(name string, value float64) FSetQueryBuilder

Field sets the object field

func (FSetQueryBuilder) IfExists

func (query FSetQueryBuilder) IfExists() FSetQueryBuilder

IfExists only set the object if it already exist

type Geofence

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

Geofence struct

func (*Geofence) Intersects

func (gf *Geofence) Intersects(key string) GeofenceAreaSelector

Intersects geofence

func (*Geofence) Nearby

func (gf *Geofence) Nearby(key string, lat, lon, meters float64) GeofenceQueryBuilder

Nearby geofence

func (*Geofence) Roam

func (gf *Geofence) Roam(key, target, pattern string, meters int, nodewell bool) GeofenceQueryBuilder

Roam geofence

func (*Geofence) Within

func (gf *Geofence) Within(key string) GeofenceAreaSelector

Within geofence

type GeofenceAreaSelector

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

GeofenceAreaSelector struct

func (GeofenceAreaSelector) Bounds

func (selector GeofenceAreaSelector) Bounds(minlat, minlon, maxlat, maxlon float64) GeofenceQueryBuilder

Bounds - a minimum bounding rectangle.

func (GeofenceAreaSelector) Circle

func (selector GeofenceAreaSelector) Circle(lat, lon, meters float64) GeofenceQueryBuilder

Circle - a circle with the specified center and radius.

func (GeofenceAreaSelector) Feature

Feature - GeoJSON Feature object.

func (GeofenceAreaSelector) FeatureCollection

func (selector GeofenceAreaSelector) FeatureCollection(fc *geojson.FeatureCollection) GeofenceQueryBuilder

FeatureCollection - GeoJSON Feature Collection object.

func (GeofenceAreaSelector) Geometry

Geometry - GeoJSON Geometry object.

func (GeofenceAreaSelector) Get

func (selector GeofenceAreaSelector) Get(key, objectID string) GeofenceQueryBuilder

Get any object that already exists in the database.

func (GeofenceAreaSelector) Hash

func (selector GeofenceAreaSelector) Hash(hash string) GeofenceQueryBuilder

Hash - a Geohash.

func (GeofenceAreaSelector) Quadkey

func (selector GeofenceAreaSelector) Quadkey(quadkey string) GeofenceQueryBuilder

Quadkey - a QuadKey.

func (GeofenceAreaSelector) Tile

func (selector GeofenceAreaSelector) Tile(x, y, z int) GeofenceQueryBuilder

Tile - an XYZ Tile.

type GeofenceEvent

type GeofenceEvent struct {
	Command string             `json:"command"`
	Hook    string             `json:"hook,omitempty"`
	Group   string             `json:"group"`
	Detect  string             `json:"detect"`
	Key     string             `json:"key"`
	Time    time.Time          `json:"time"`
	ID      string             `json:"id"`
	Object  *Object            `json:"object,omitempty"`
	Point   *Point             `json:"point,omitempty"`
	Bounds  *Bounds            `json:"bounds,omitempty"`
	Hash    *string            `json:"hash,omitempty"`
	Nearby  *RoamObject        `json:"nearby,omitempty"`
	Faraway *RoamObject        `json:"faraway,omitempty"`
	Fields  map[string]float64 `json:"fields,omitempty"`
}

GeofenceEvent is a tile38 geofence event.

type GeofenceQueryBuilder

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

GeofenceQueryBuilder optional params

func (GeofenceQueryBuilder) Actions

func (query GeofenceQueryBuilder) Actions(actions ...DetectAction) GeofenceQueryBuilder

Actions sets the geofence actions. All actions used by default.

func (GeofenceQueryBuilder) Clip

Clip tells the server to clip intersecting objects by the bounding box area of the search. It can only be used with these area formats: BOUNDS, TILE, QUADKEY, HASH.

func (GeofenceQueryBuilder) Commands

func (query GeofenceQueryBuilder) Commands(notifyCommands ...NotifyCommand) GeofenceQueryBuilder

Commands sets the geofence commands.

func (GeofenceQueryBuilder) Cursor

func (query GeofenceQueryBuilder) Cursor(cursor int) GeofenceQueryBuilder

Cursor is used to iterate though many objects from the search results. An iteration begins when the CURSOR is set to Zero or not included with the request, and completes when the cursor returned by the server is Zero.

func (GeofenceQueryBuilder) Distance

func (query GeofenceQueryBuilder) Distance() GeofenceQueryBuilder

Distance allows to return between objects. Only for NEARBY tileCmd.

func (GeofenceQueryBuilder) Do

func (query GeofenceQueryBuilder) Do(ctx context.Context, handler EventHandler) error

Do cmd

func (GeofenceQueryBuilder) Format

Format set response format.

func (GeofenceQueryBuilder) Limit

func (query GeofenceQueryBuilder) Limit(limit int) GeofenceQueryBuilder

Limit can be used to limit the number of objects returned for a single search request.

func (GeofenceQueryBuilder) Match

func (query GeofenceQueryBuilder) Match(pattern string) GeofenceQueryBuilder

Match is similar to WHERE except that it works on the object id instead of fields. There can be multiple MATCH options in a single search. The MATCH value is a simple glob pattern.

func (GeofenceQueryBuilder) NoFields

func (query GeofenceQueryBuilder) NoFields() GeofenceQueryBuilder

NoFields tells the server that you do not want field values returned with the search results.

func (GeofenceQueryBuilder) Sparse

func (query GeofenceQueryBuilder) Sparse(sparse int) GeofenceQueryBuilder

Sparse will distribute the results of a search evenly across the requested area.

func (GeofenceQueryBuilder) Where

func (query GeofenceQueryBuilder) Where(field string, min, max float64) GeofenceQueryBuilder

Where allows for filtering out results based on field values.

func (GeofenceQueryBuilder) WhereEval

func (query GeofenceQueryBuilder) WhereEval(script string, args ...string) GeofenceQueryBuilder

WhereEval similar to WHERE except that matching decision is made by Lua script For example: 'nearby fleet whereeval "return FIELDS.wheels > ARGV[1] or (FIELDS.length * FIELDS.width) > ARGV[2]" 2 8 120 point 33.462 -112.268 6000' will return only the objects in the fleet collection that are within the 6km radius and have a field named wheels that is above 8, or have length and width whose product is greater than 120. Multiple WHEREEVALs are concatenated as and clauses. See EVAL command for more details. Note that, unlike the EVAL command, WHEREVAL Lua environment (1) does not have KEYS global, and (2) has the FIELDS global with the Lua table of the iterated object’s fields.

func (GeofenceQueryBuilder) WhereEvalSHA

func (query GeofenceQueryBuilder) WhereEvalSHA(sha string, args ...string) GeofenceQueryBuilder

WhereEvalSHA similar to WHERE except that matching decision is made by Lua script For example: 'nearby fleet whereeval "return FIELDS.wheels > ARGV[1] or (FIELDS.length * FIELDS.width) > ARGV[2]" 2 8 120 point 33.462 -112.268 6000' will return only the objects in the fleet collection that are within the 6km radius and have a field named wheels that is above 8, or have length and width whose product is greater than 120. Multiple WHEREEVALs are concatenated as and clauses. See EVAL command for more details. Note that, unlike the EVAL command, WHEREVAL Lua environment (1) does not have KEYS global, and (2) has the FIELDS global with the Lua table of the iterated object’s fields.

func (GeofenceQueryBuilder) Wherein

func (query GeofenceQueryBuilder) Wherein(field string, values ...float64) GeofenceQueryBuilder

Wherein is similar to Where except that it checks whether the object’s field value is in a given list.

type GetBoundsResponse added in v0.10.0

type GetBoundsResponse struct {
	Bounds Bounds             `json:"bounds"`
	Fields map[string]float64 `json:"fields"`
}

type GetHashResponse added in v0.10.0

type GetHashResponse struct {
	Hash   string             `json:"hash"`
	Fields map[string]float64 `json:"fields"`
}

type GetObjectResponse added in v0.10.0

type GetObjectResponse struct {
	Object Object             `json:"object"`
	Fields map[string]float64 `json:"fields"`
}

type GetPointResponse added in v0.10.0

type GetPointResponse struct {
	Point  Point              `json:"point"`
	Fields map[string]float64 `json:"fields"`
}

type Hook

type Hook struct {
	Endpoints []string `json:"endpoints"`
	Chan
}

Hook represents tile38 channel.

type Hooks

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

Hooks struct

func (*Hooks) DelHook

func (hooks *Hooks) DelHook(ctx context.Context, name string) error

DelHook remove a specified hook.

func (*Hooks) Hooks

func (hooks *Hooks) Hooks(ctx context.Context, pattern string) ([]Hook, error)

Hooks returns all hooks matching pattern.

func (*Hooks) PDelHook

func (hooks *Hooks) PDelHook(ctx context.Context, pattern string) error

PDelHook removes all hooks that match the specified pattern.

func (*Hooks) SetHook

func (hooks *Hooks) SetHook(name, endpoint string, query GeofenceQueryBuilder) SetHookQueryBuilder

SetHook creates a webhook which points to a geofenced search. If a hook is already associated to that name, it’ll be overwritten.

type InwAreaSelector

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

InwAreaSelector struct Intersects Nearby Within

func (InwAreaSelector) Bounds

func (selector InwAreaSelector) Bounds(minlat, minlon, maxlat, maxlon float64) InwQueryBuilder

Bounds - a minimum bounding rectangle.

func (InwAreaSelector) Circle

func (selector InwAreaSelector) Circle(lat, lon, meters float64) InwQueryBuilder

Circle - a circle with the specified center and radius.

func (InwAreaSelector) Feature

func (selector InwAreaSelector) Feature(ft *geojson.Feature) InwQueryBuilder

Feature - GeoJSON Feature object.

func (InwAreaSelector) FeatureCollection

func (selector InwAreaSelector) FeatureCollection(fc *geojson.FeatureCollection) InwQueryBuilder

FeatureCollection - GeoJSON Feature Collection object.

func (InwAreaSelector) Geometry

func (selector InwAreaSelector) Geometry(gm *geojson.Geometry) InwQueryBuilder

Geometry - GeoJSON Geometry object.

func (InwAreaSelector) Get

func (selector InwAreaSelector) Get(key, objectID string) InwQueryBuilder

Get any object that already exists in the database.

func (InwAreaSelector) Hash

func (selector InwAreaSelector) Hash(hash string) InwQueryBuilder

Hash - a Geohash.

func (InwAreaSelector) Quadkey

func (selector InwAreaSelector) Quadkey(quadkey string) InwQueryBuilder

Quadkey - a QuadKey.

func (InwAreaSelector) Tile

func (selector InwAreaSelector) Tile(x, y, z int) InwQueryBuilder

Tile - an XYZ Tile.

type InwQueryBuilder

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

InwQueryBuilder struct Intersects Nearby Within

func (InwQueryBuilder) Clip

func (query InwQueryBuilder) Clip() InwQueryBuilder

Clip tells the server to clip intersecting objects by the bounding box area of the search. It can only be used with these area formats: BOUNDS, TILE, QUADKEY, HASH. Only for INTERSECTS command.

func (InwQueryBuilder) Cursor

func (query InwQueryBuilder) Cursor(cursor int) InwQueryBuilder

Cursor is used to iterate though many objects from the search results. An iteration begins when the CURSOR is set to Zero or not included with the request, and completes when the cursor returned by the server is Zero.

func (InwQueryBuilder) Distance

func (query InwQueryBuilder) Distance() InwQueryBuilder

Distance allows to return between objects. Only for NEARBY command.

func (InwQueryBuilder) Do

Do cmd

func (InwQueryBuilder) Format

func (query InwQueryBuilder) Format(fmt OutputFormat) InwQueryBuilder

Format set response format.

func (InwQueryBuilder) Limit

func (query InwQueryBuilder) Limit(limit int) InwQueryBuilder

Limit can be used to limit the number of objects returned for a single search request.

func (InwQueryBuilder) Match

func (query InwQueryBuilder) Match(pattern string) InwQueryBuilder

Match is similar to WHERE except that it works on the object id instead of fields. There can be multiple MATCH options in a single search. The MATCH value is a simple glob pattern.

func (InwQueryBuilder) NoFields

func (query InwQueryBuilder) NoFields() InwQueryBuilder

NoFields tells the server that you do not want field values returned with the search results.

func (InwQueryBuilder) Sparse

func (query InwQueryBuilder) Sparse(sparse int) InwQueryBuilder

Sparse will distribute the results of a search evenly across the requested area.

func (InwQueryBuilder) Where

func (query InwQueryBuilder) Where(field string, min, max float64) InwQueryBuilder

Where allows for filtering out results based on field values.

func (InwQueryBuilder) WhereEval

func (query InwQueryBuilder) WhereEval(script string, args ...string) InwQueryBuilder

WhereEval similar to WHERE except that matching decision is made by Lua script For example: 'nearby fleet whereeval "return FIELDS.wheels > ARGV[1] or (FIELDS.length * FIELDS.width) > ARGV[2]" 2 8 120 point 33.462 -112.268 6000' will return only the objects in the fleet collection that are within the 6km radius and have a field named wheels that is above 8, or have length and width whose product is greater than 120. Multiple WHEREEVALs are concatenated as and clauses. See EVAL command for more details. Note that, unlike the EVAL command, WHEREVAL Lua environment (1) does not have KEYS global, and (2) has the FIELDS global with the Lua table of the iterated object’s fields.

func (InwQueryBuilder) WhereEvalSHA

func (query InwQueryBuilder) WhereEvalSHA(sha string, args ...string) InwQueryBuilder

WhereEvalSHA similar to WHERE except that matching decision is made by Lua script For example: 'nearby fleet whereeval "return FIELDS.wheels > ARGV[1] or (FIELDS.length * FIELDS.width) > ARGV[2]" 2 8 120 point 33.462 -112.268 6000' will return only the objects in the fleet collection that are within the 6km radius and have a field named wheels that is above 8, or have length and width whose product is greater than 120. Multiple WHEREEVALs are concatenated as and clauses. See EVAL command for more details. Note that, unlike the EVAL command, WHEREVAL Lua environment (1) does not have KEYS global, and (2) has the FIELDS global with the Lua table of the iterated object’s fields.

func (InwQueryBuilder) Wherein

func (query InwQueryBuilder) Wherein(field string, values ...float64) InwQueryBuilder

Wherein is similar to Where except that it checks whether the object’s field value is in a given list.

type JSetQueryBuilder

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

JSetQueryBuilder struct

func (JSetQueryBuilder) Do

func (query JSetQueryBuilder) Do(ctx context.Context) error

Do cmd

func (JSetQueryBuilder) Raw

func (query JSetQueryBuilder) Raw() JSetQueryBuilder

Raw allows value to be interpreted as a serialized JSON object

func (JSetQueryBuilder) Str

func (query JSetQueryBuilder) Str() JSetQueryBuilder

Str allows value to be interpreted as a string

type KeyStats

type KeyStats struct {
	InMemorySize int `json:"in_memory_size"`
	NumObjects   int `json:"num_objects"`
	NumPoints    int `json:"num_points"`
}

KeyStats is a tile38 key stats.

type Keys

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

Keys struct

func (*Keys) Bounds

func (ks *Keys) Bounds(ctx context.Context, key string) ([][][]float64, error)

Bounds returns the minimum bounding rectangle for all objects in a key.

func (*Keys) Del

func (ks *Keys) Del(ctx context.Context, key, objectID string) error

Del remove a specified object.

func (*Keys) Drop

func (ks *Keys) Drop(ctx context.Context, key string) error

Drop remove all objects from specified key.

func (*Keys) Expire

func (ks *Keys) Expire(ctx context.Context, key, objectID string, seconds int) error

Expire set a timeout on an id.

func (*Keys) FSet

func (ks *Keys) FSet(key, objectID string) FSetQueryBuilder

FSet set the value for one or more fields of an id. Fields are double precision floating points. Normally, FSET will return an error if the field is being set on a non-existent id. However, the option XX can alter this behavior. Specifically, if called with XX option, FSET will return 0 when called on a non-existend id. Note that the non-existent key will still cause an error!

func (*Keys) Get

func (ks *Keys) Get(key, objectID string) KeysGetQueryBuilder

Get returns object of an id.

func (*Keys) JDel

func (ks *Keys) JDel(ctx context.Context, key, objectID, path string) error

JDel delete a value from a JSON document.

func (*Keys) JGet

func (ks *Keys) JGet(ctx context.Context, key, objectID, path string) ([]byte, error)

JGet get a value from a JSON document.

func (*Keys) JSet

func (ks *Keys) JSet(key, objectID, path, value string) JSetQueryBuilder

JSet set a value in a JSON document.

func (*Keys) Keys

func (ks *Keys) Keys(ctx context.Context, pattern string) ([]string, error)

Keys returns all keys matching pattern.

func (*Keys) PDel

func (ks *Keys) PDel(ctx context.Context, key, pattern string) error

PDel removes objects that match a specified pattern.

func (*Keys) Persist

func (ks *Keys) Persist(ctx context.Context, key, objectID string) error

Persist remove an existing timeout of an id.

func (*Keys) Rename

func (ks *Keys) Rename(ctx context.Context, key, newKey string) error

Rename renames collection key to newkey. If newkey already exists, it will be deleted prior to renaming. Returns “OK” for success or “ERR” when key or newkey are actively being used by a geofence or webhook.

func (*Keys) RenameNX

func (ks *Keys) RenameNX(ctx context.Context, key, newKey string) error

RenameNX renames collection key to newkey, if it does not exist yet. If newkey already exists, this command does nothing. Returns 1 if key was renamed to newkey, 0 if newkey already existed, or “ERR” when key or newkey are actively being used by a geofence or webhook.

func (*Keys) Set

func (ks *Keys) Set(key, objectID string) SetAreaSelector

Set the value of an id. If a value is already associated to that key/id, it’ll be overwritten.

func (*Keys) Stats

func (ks *Keys) Stats(ctx context.Context, keys ...string) ([]KeyStats, error)

Stats return stats for one or more keys.

func (*Keys) TTL

func (ks *Keys) TTL(ctx context.Context, key, objectID string) (int, error)

TTL get a timeout on an id.

type KeysGetQueryBuilder added in v0.10.0

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

func (KeysGetQueryBuilder) Bounds added in v0.10.0

func (KeysGetQueryBuilder) Hash added in v0.10.0

func (q KeysGetQueryBuilder) Hash(ctx context.Context, precision int) (*GetHashResponse, error)

func (KeysGetQueryBuilder) Object added in v0.10.0

func (KeysGetQueryBuilder) Point added in v0.10.0

func (KeysGetQueryBuilder) WithFields added in v0.10.0

type Meta

type Meta struct {
	Name  string
	Value string
}

Meta is tile38 metadata.

type NotifyCommand

type NotifyCommand string

NotifyCommand ...

const (
	// Del notifies the client that an object has been deleted from the collection that is being fenced.
	Del NotifyCommand = "del"
	// Drop notifies the client that the entire collection is dropped.
	Drop NotifyCommand = "drop"
	// Set notifies the client that an object has been added or updated,
	// and when it’s position is detected by the fence.
	Set NotifyCommand = "set"
)

type Object

type Object struct {
	FeatureCollection *geojson.FeatureCollection `json:"featureCollection,omitempty"`
	Feature           *geojson.Feature           `json:"feature,omitempty"`
	Geometry          *geojson.Geometry          `json:"geometry,omitempty"`
	String            *string                    `json:"string,omitempty"`
}

Object is a tile38 object.

func (*Object) UnmarshalJSON

func (ob *Object) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals object from the given json data.

type OutputFormat

type OutputFormat cmd

OutputFormat specifies expected format.

type Point

type Point struct {
	Lat float64 `json:"lat"`
	Lon float64 `json:"lon"`
}

Point is a tile38 point.

type RoamObject

type RoamObject struct {
	Key    string  `json:"key"`
	ID     string  `json:"id"`
	Object Object  `json:"object"`
	Meters float64 `json:"meters"`
}

RoamObject is a tile38 roam object.

type ScanQueryBuilder

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

ScanQueryBuilder struct

func (ScanQueryBuilder) Asc

func (query ScanQueryBuilder) Asc() ScanQueryBuilder

Asc order. Only for SEARCH and SCAN commands.

func (ScanQueryBuilder) Cursor

func (query ScanQueryBuilder) Cursor(cursor int) ScanQueryBuilder

Cursor is used to iterate though many objects from the search results. An iteration begins when the CURSOR is set to Zero or not included with the request, and completes when the cursor returned by the server is Zero.

func (ScanQueryBuilder) Desc

func (query ScanQueryBuilder) Desc() ScanQueryBuilder

Desc order. Only for SEARCH and SCAN commands.

func (ScanQueryBuilder) Do

Do cmd

func (ScanQueryBuilder) Format

Format set response format.

func (ScanQueryBuilder) Limit

func (query ScanQueryBuilder) Limit(limit int) ScanQueryBuilder

Limit can be used to limit the number of objects returned for a single search request.

func (ScanQueryBuilder) Match

func (query ScanQueryBuilder) Match(pattern string) ScanQueryBuilder

Match is similar to WHERE except that it works on the object id instead of fields. There can be multiple MATCH options in a single search. The MATCH value is a simple glob pattern.

func (ScanQueryBuilder) NoFields

func (query ScanQueryBuilder) NoFields() ScanQueryBuilder

NoFields tells the server that you do not want field values returned with the search results.

func (ScanQueryBuilder) Where

func (query ScanQueryBuilder) Where(field string, min, max float64) ScanQueryBuilder

Where allows for filtering out results based on field values.

func (ScanQueryBuilder) Wherein

func (query ScanQueryBuilder) Wherein(field string, values ...float64) ScanQueryBuilder

Wherein is similar to Where except that it checks whether the object’s field value is in a given list.

type Scripting

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

Scripting struct

func (*Scripting) Eval

func (sc *Scripting) Eval(ctx context.Context, script string, keys []string, args []string) ([]byte, error)

Eval evaluates a Lua script

func (*Scripting) EvalNA

func (sc *Scripting) EvalNA(ctx context.Context, script string, keys []string, args []string) ([]byte, error)

EvalNA evaluates a Lua script in a non-atomic fashion. The command uses None atomicity level and is otherwise identical to EVAL.

func (*Scripting) EvalNASHA

func (sc *Scripting) EvalNASHA(ctx context.Context, sha string, keys []string, args []string) ([]byte, error)

EvalNASHA evaluates, in a non-atomic fashion, a Lua script cached on the server by its SHA1 digest. Scripts are cached using the SCRIPT LOAD command. The command is otherwise identical to EVALNA.

func (*Scripting) EvalRO

func (sc *Scripting) EvalRO(ctx context.Context, script string, keys []string, args []string) ([]byte, error)

EvalRO evaluates a read-only Lua script. The command uses Read-only atomicity level and is otherwise identical to EVAL.

func (*Scripting) EvalROSHA

func (sc *Scripting) EvalROSHA(ctx context.Context, sha string, keys []string, args []string) ([]byte, error)

EvalROSHA evaluates a read-only Lua script cached on the server by its SHA1 digest. Scripts are cached using the SCRIPT LOAD command. The command is otherwise identical to EVALRO.

func (*Scripting) EvalSHA

func (sc *Scripting) EvalSHA(ctx context.Context, sha string, keys []string, args []string) ([]byte, error)

EvalSHA evaluates a Lua script cached on the server by its SHA1 digest. Scripts are cached using the SCRIPT LOAD command. The command is otherwise identical to EVAL.

func (*Scripting) ScriptExists

func (sc *Scripting) ScriptExists(ctx context.Context, shas ...string) ([]int, error)

ScriptExists returns information about the existence of the scripts in server cache. This command takes one or more SHA1 digests and returns a list of one/zero integer values to indicate whether or not each SHA1 exists in the server script cache. Scripts are cached using the SCRIPT LOAD command.

func (*Scripting) ScriptFlush

func (sc *Scripting) ScriptFlush(ctx context.Context) error

ScriptFlush flushes the server cache of Lua scripts.

func (*Scripting) ScriptLoad

func (sc *Scripting) ScriptLoad(ctx context.Context, script string) error

ScriptLoad loads the compiled version of a script into the server cache, without executing. If the parsing and compilation is successful, the command returns the string value of the SHA1 digest of the script. That value can be used for EVALSHA and similar commands that execute scripts based on the SHA1 digest. The script will stay in cache until either the tile38 is restarted or SCRIPT FLUSH is called. If either parsing or compilation fails, the command will return the error response with the detailed traceback of the Lua failure.

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

Search struct

func (*Search) Intersects

func (search *Search) Intersects(key string) InwAreaSelector

Intersects searches a collection for objects that intersect a specified bounding area.

func (*Search) Nearby

func (search *Search) Nearby(key string, lat, lon, meters float64) InwQueryBuilder

Nearby command searches a collection for objects that are close to a specified point. The KNN algorithm is used instead of the standard overlap+Haversine algorithm, sorting the results in order of ascending distance from that point, i.e., nearest first.

func (*Search) Scan

func (search *Search) Scan(key string) ScanQueryBuilder

Scan incrementally iterates though a key.

func (*Search) Search

func (search *Search) Search(key string) SearchQueryBuilder

Search iterates though a key’s string values.

func (*Search) Within

func (search *Search) Within(key string) InwAreaSelector

Within searches a collection for objects that are fully contained inside of a specified bounding area.

type SearchQueryBuilder

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

SearchQueryBuilder struct

func (SearchQueryBuilder) Asc

Asc order. Only for SEARCH and SCAN commands.

func (SearchQueryBuilder) Cursor

func (query SearchQueryBuilder) Cursor(cursor int) SearchQueryBuilder

Cursor is used to iterate though many objects from the search results. An iteration begins when the CURSOR is set to Zero or not included with the request, and completes when the cursor returned by the server is Zero.

func (SearchQueryBuilder) Desc

Desc order. Only for SEARCH and SCAN commands.

func (SearchQueryBuilder) Do

Do cmd

func (SearchQueryBuilder) FormatCount

func (query SearchQueryBuilder) FormatCount() SearchQueryBuilder

FormatCount - total object count sent in the response.

func (SearchQueryBuilder) FormatIDs

func (query SearchQueryBuilder) FormatIDs() SearchQueryBuilder

FormatIDs - a list of IDs belonging to the key. Will not return the objects.

func (SearchQueryBuilder) Limit

func (query SearchQueryBuilder) Limit(limit int) SearchQueryBuilder

Limit can be used to limit the number of objects returned for a single search request.

func (SearchQueryBuilder) Match

func (query SearchQueryBuilder) Match(pattern string) SearchQueryBuilder

Match is similar to WHERE except that it works on the object id instead of fields. There can be multiple MATCH options in a single search. The MATCH value is a simple glob pattern.

func (SearchQueryBuilder) NoFields

func (query SearchQueryBuilder) NoFields() SearchQueryBuilder

NoFields tells the server that you do not want field values returned with the search results.

func (SearchQueryBuilder) Where

func (query SearchQueryBuilder) Where(field string, min, max float64) SearchQueryBuilder

Where allows for filtering out results based on field values.

func (SearchQueryBuilder) Wherein

func (query SearchQueryBuilder) Wherein(field string, values ...float64) SearchQueryBuilder

Wherein is similar to Where except that it checks whether the object’s field value is in a given list.

type SearchResponse

type SearchResponse struct {
	Cursor  int      `json:"cursor"`
	Count   int      `json:"count"`
	Fields  []string `json:"fields,omitempty"`
	Objects []struct {
		ID       string    `json:"ID"`
		Object   Object    `json:"object"`
		Fields   []float64 `json:"fields,omitempty"`
		Distance *float64  `json:"distance,omitempty"`
	} `json:"objects,omitempty"`
	Points []struct {
		ID       string    `json:"ID"`
		Point    Point     `json:"point"`
		Fields   []float64 `json:"fields,omitempty"`
		Distance *float64  `json:"distance,omitempty"`
	} `json:"points,omitempty"`
	Bounds []struct {
		ID       string    `json:"ID"`
		Bounds   Bounds    `json:"bounds"`
		Fields   []float64 `json:"fields,omitempty"`
		Distance *float64  `json:"distance,omitempty"`
	} `json:"bounds,omitempty"`
	Hashes []struct {
		ID       string    `json:"id"`
		Hash     string    `json:"hash"`
		Fields   []float64 `json:"fields,omitempty"`
		Distance *float64  `json:"distance,omitempty"`
	} `json:"hashes,omitempty"`
	IDs []string `json:"ids,omitempty"`
}

SearchResponse is a tile38 search response.

type Server added in v0.9.6

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

func (*Server) FlushDB added in v0.9.6

func (sv *Server) FlushDB(ctx context.Context) error

WARNING: This erases all data in Tile38 DB!

type SetAreaSelector

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

SetAreaSelector struct

func (SetAreaSelector) Bounds

func (selector SetAreaSelector) Bounds(lat1, lon1, lat2, lon2 float64) SetQueryBuilder

Bounds - a bounding box consists of two points. The first being the southwestern most point and the second is the northeastern most point.

func (SetAreaSelector) Feature

func (selector SetAreaSelector) Feature(ft *geojson.Feature) SetQueryBuilder

Feature - set GeoJSON Feature object.

func (SetAreaSelector) FeatureCollection

func (selector SetAreaSelector) FeatureCollection(fc *geojson.FeatureCollection) SetQueryBuilder

FeatureCollection - set GeoJSON Feature Collection object.

func (SetAreaSelector) Geometry

func (selector SetAreaSelector) Geometry(gm *geojson.Geometry) SetQueryBuilder

Geometry - set GeoJSON Geometry object.

func (SetAreaSelector) Hash

func (selector SetAreaSelector) Hash(hash string) SetQueryBuilder

Hash - A geohash is a convenient way of expressing a location (anywhere in the world) using a short alphanumeric string, with greater precision obtained with longer strings.

func (SetAreaSelector) Point

func (selector SetAreaSelector) Point(lat, lon float64) SetQueryBuilder

Point set a simple point in latitude, longitude.

func (SetAreaSelector) PointZ

func (selector SetAreaSelector) PointZ(lat, lon, z float64) SetQueryBuilder

PointZ - a point with Z coordinate. This is application specific such as elevation, or a timestamp, etc.

func (SetAreaSelector) String

func (selector SetAreaSelector) String(str string) SetQueryBuilder

String - It’s possible to set a raw string. The value of a string type can be plain text or a series of raw bytes. To retrieve a string value you can use GET, SCAN, or SEARCH.

type SetChannelQueryBuilder

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

SetChannelQueryBuilder struct

func (SetChannelQueryBuilder) Do

Do cmd

func (SetChannelQueryBuilder) Expiration

func (query SetChannelQueryBuilder) Expiration(seconds int) SetChannelQueryBuilder

Expiration set the specified expire time, in seconds.

func (SetChannelQueryBuilder) Meta

func (query SetChannelQueryBuilder) Meta(name, value string) SetChannelQueryBuilder

Meta ...

type SetHookQueryBuilder

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

SetHookQueryBuilder struct

func (SetHookQueryBuilder) Do

func (query SetHookQueryBuilder) Do(ctx context.Context) error

Do cmd

func (SetHookQueryBuilder) Endpoint

func (query SetHookQueryBuilder) Endpoint(endpoint string) SetHookQueryBuilder

Endpoint appends new endpoint to the hook. Tile38 will try to send a message to the first endpoint. If the send is a failure then the second endpoint is tried, and so on.

func (SetHookQueryBuilder) Expiration

func (query SetHookQueryBuilder) Expiration(seconds int) SetHookQueryBuilder

Expiration set the specified expire time, in seconds.

func (SetHookQueryBuilder) Meta

func (query SetHookQueryBuilder) Meta(name, value string) SetHookQueryBuilder

Meta ...

type SetQueryBuilder

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

SetQueryBuilder struct

func (SetQueryBuilder) Do

func (query SetQueryBuilder) Do(ctx context.Context) error

Do cmd

func (SetQueryBuilder) Expiration

func (query SetQueryBuilder) Expiration(seconds int) SetQueryBuilder

Expiration sets the specified expire time, in seconds

func (SetQueryBuilder) Field

func (query SetQueryBuilder) Field(name string, value float64) SetQueryBuilder

Field sets the object field

func (SetQueryBuilder) IfExists

func (query SetQueryBuilder) IfExists() SetQueryBuilder

IfExists only set the object if it already exist

func (SetQueryBuilder) IfNotExists

func (query SetQueryBuilder) IfNotExists() SetQueryBuilder

IfNotExists only set the object if it does not already exist

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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