client

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: Apache-2.0 Imports: 13 Imported by: 1

README

GoDoc

Letarette client library for Golang

Letarette docs

Installation

go get -u github.com/erkkah/letarette

Example

package main

import (
	"fmt"

	"github.com/erkkah/letarette/pkg/client"
)

func main() {
	agent, err := client.NewSearchAgent([]string{"nats://localhost:4222"})
	if err != nil {
		fmt.Printf("NATS connection failed: %v", err)
		return
	}
	defer agent.Close()

	spaces := []string{"fruits"}
	pageLimit := 10
	pageOffset := 0

	res, err := agent.Search("apple", spaces, pageLimit, pageOffset)
	if err != nil {
		fmt.Printf("Search request failed: %v", err)
		return
	}

	for _, hit := range res.Result.Hits {
		fmt.Println(hit.Snippet)
	}
}


Documentation

Index

Constants

View Source
const COMPRESSED_ENCODER = "COMPRESSED_ENCODER"
View Source
const COMPRESSION_LIMIT = 1024
View Source
const COMPRESSION_MARKER = uint8(0xf8)

Variables

This section is empty.

Functions

This section is empty.

Types

type CompressedJSONEncoder added in v0.2.0

type CompressedJSONEncoder struct{}

func (CompressedJSONEncoder) Decode added in v0.2.0

func (e CompressedJSONEncoder) Decode(subject string, data []byte, valuePointer interface{}) error

func (CompressedJSONEncoder) Encode added in v0.2.0

func (e CompressedJSONEncoder) Encode(subject string, value interface{}) ([]byte, error)

type DocumentManager

type DocumentManager interface {
	Close()
	StartIndexRequestHandler(handler IndexRequestHandler) error
	StartDocumentRequestHandler(handler DocumentRequestHandler) error
}

DocumentManager connects to the letarette cluster and processes indexing requests

func StartDocumentManager

func StartDocumentManager(URLs []string, options ...Option) (DocumentManager, error)

StartDocumentManager creates a DocumentManager and connects to Nats daemon

type DocumentRequestHandler

type DocumentRequestHandler func(ctx context.Context, req protocol.DocumentRequest) (protocol.DocumentUpdate, error)

DocumentRequestHandler processes document requests from the letarette cluster and returns document updates.

type IndexRequestHandler

type IndexRequestHandler func(ctx context.Context, req protocol.IndexUpdateRequest) (protocol.IndexUpdate, error)

IndexRequestHandler processes index update requests from the letarette cluster and returns index updates.

type MetricsCollector added in v0.2.0

type MetricsCollector func(metrics protocol.Metrics)

MetricsCollector is a callback function receiving metrics updates

type Monitor

type Monitor interface {
	Close()
}

Monitor listens to status broadcasts from a letarette cluster

func NewMonitor

func NewMonitor(URLs []string, listener MonitorListener, options ...Option) (Monitor, error)

NewMonitor - Monitor constructor

type MonitorListener

type MonitorListener func(protocol.IndexStatus)

MonitorListener is a callback function receiving status broadcasts

type Option

type Option func(*state)

Option is the option setter interface. See related WithXXX functions.

func WithErrorHandler

func WithErrorHandler(handler func(error)) Option

WithErrorHandler sets an error handler instead of the default silent one

func WithMetricsCollector added in v0.2.0

func WithMetricsCollector(collector MetricsCollector, interval time.Duration) Option

WithMetricsCollector makes the monitor periodically request metrics from the cluster.

func WithRootCAs

func WithRootCAs(rootCAFiles ...string) Option

WithRootCAs specifies a set of root CA files for server verification

func WithSeedFile

func WithSeedFile(seedFile string) Option

WithSeedFile specifies a seed file for Nkey authentication

func WithShardgroupSize

func WithShardgroupSize(groupSize int32) Option

WithShardgroupSize forces shard group size instead of using discovery

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets search request timeout

func WithTopic

func WithTopic(topic string) Option

WithTopic sets the Nats topic instead of the default

type SearchAgent

type SearchAgent interface {
	Close()
	Search(q string, spaces []string, pageLimit int, pageOffset int) (protocol.SearchResponse, error)
}

SearchAgent is a letarette cluster searcher

func NewSearchAgent

func NewSearchAgent(URLs []string, options ...Option) (SearchAgent, error)

NewSearchAgent - SearchAgent constructor

Jump to

Keyboard shortcuts

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