plugin

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2021 License: MPL-2.0 Imports: 20 Imported by: 28

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContextKeyLogger = contextKey("logger")
)

Functions

func Logger

func Logger(ctx context.Context) hclog.Logger

func Serve

func Serve(opts *ServeOpts)

func ToError added in v0.1.1

func ToError(val interface{}) error

remove once go-kit version 0.2.0 is released ToError :: if supplied value is already an error, return it, otherwise format it as an error

Types

type Column

type Column struct {
	// column name
	Name string
	// column type
	Type proto.ColumnType
	// column description
	Description string
	// explicitly specify the function which populates this data
	// - this is only needed if any of the default hydrate functions wil NOT return this column
	Hydrate HydrateFunc

	// the default column value
	Default interface{}
	//  a list of transforms to generate the column value
	Transform *transform.ColumnTransforms
	// contains filtered or unexported fields
}

Column :: column data, in format compatible with proto ColumnDefinition

type ConcurrencyManager added in v0.1.1

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

ConcurrencyManager :: struct which ensures hydrate funcitons stay within concurrency limits

func (*ConcurrencyManager) Finished added in v0.1.1

func (c *ConcurrencyManager) Finished(name string)

Finished :: decrement the counter for the named function

func (*ConcurrencyManager) StartIfAllowed added in v0.1.1

func (c *ConcurrencyManager) StartIfAllowed(name string, maxCallConcurrency int) (res bool)

StartIfAllowed :: check whether the named hydrate call is permitted to start based on the number of running instances of that call, and the total calls in progress

type DefaultHydrateConfig added in v0.1.1

type DefaultHydrateConfig struct {
	// max number of ALL hydrate calls in progress
	MaxConcurrency               int
	DefaultMaxConcurrencyPerCall int
}

DefaultHydrateConfig :: plugin levelk config to define default hydrate concurrency - used if no HydrateConfig is specified for a specific call

type ErrorPredicate

type ErrorPredicate func(error) bool

type GetConfig

type GetConfig struct {
	// key or keys which are used to uniquely identify rows - used to determine whether  a query is a 'get' call
	KeyColumns  *KeyColumnSet
	ItemFromKey HydrateFunc
	// the hydrate function which is called first when performing a 'get' call.
	// if this returns 'not found', no further hydrate functions are called
	Hydrate HydrateFunc
	// a function which will return whenther to ignore a given error
	ShouldIgnoreError ErrorPredicate
}

type HydrateCall

type HydrateCall struct {
	Func HydrateFunc
	// the dependencies expressed using function name
	Depends []string
	Config  *HydrateConfig
}

HydrateCall :: struct encapsulating a hydrate call, its config and dependencies

func (HydrateCall) CanStart

func (h HydrateCall) CanStart(rowData *RowData, name string, concurrencyManager *ConcurrencyManager) bool

func (*HydrateCall) Start added in v0.1.1

func (h *HydrateCall) Start(ctx context.Context, r *RowData, hydrateFuncName string, concurrencyManager *ConcurrencyManager)

Start :: start a hydrate call

type HydrateConfig added in v0.1.1

type HydrateConfig struct {
	Func           HydrateFunc
	MaxConcurrency int
	// ConcurrencyMapKey ConcurrencyMapKeyFunc
	// ShouldRetryError ErrorPredicate
	// ShouldIgnoreError ErrorPredicate
	Depends []HydrateFunc
}

HydrateConfig :: define the hydrate function configurations, Name, Maximum number of concurrent calls to be allowed, dependencies

type HydrateData

type HydrateData struct {
	Item           interface{}
	HydrateResults map[string]interface{}
}

HydrateData :: the input data passed to every hydrate function

type HydrateDependencies

type HydrateDependencies struct {
	Func    HydrateFunc
	Depends []HydrateFunc
}

HydrateDependencies :: define the hydrate function dependencies - other hydrate functions which must be run first Deprecated: used HydrateConfig

type HydrateFunc

type HydrateFunc func(context.Context, *QueryData, *HydrateData) (interface{}, error)

HydrateFunc :: a function which retrieves some or all row data for a single row item.

type KeyColumnSet

type KeyColumnSet struct {
	Single string
	All    []string
	Any    []string
}

KeyColumnSet :: a set of columns which form the key of a table (i.e. may be used to get a single item) may specify: - a Single column - a set of columns which together All form the key - a set of columns Any of which which form the key

func AllColumns

func AllColumns(columns []string) *KeyColumnSet

func AnyColumn

func AnyColumn(columns []string) *KeyColumnSet

func SingleColumn

func SingleColumn(column string) *KeyColumnSet

func (*KeyColumnSet) ToString

func (k *KeyColumnSet) ToString() string

type ListConfig

type ListConfig struct {
	KeyColumns *KeyColumnSet
	// the list function, this should stream the list results back using the QueryData object, and return nil
	Hydrate HydrateFunc
	// the parent list function - if we list items with a parent-child relationship, this will list the parent items
	ParentHydrate HydrateFunc
}

type Plugin

type Plugin struct {
	Name                 string
	Logger               hclog.Logger
	TableMap             map[string]*Table
	DefaultTransform     *transform.ColumnTransforms
	DefaultGetConfig     *GetConfig
	DefaultHydrateConfig *DefaultHydrateConfig
	// every table must implement these columns
	RequiredColumns []*Column
}

Plugin :: an object used to build all necessary data for a given query

func (*Plugin) Execute

func (p *Plugin) Execute(req *proto.ExecuteRequest, stream proto.WrapperPlugin_ExecuteServer) (err error)

Execute :: execute a query and stream the results

func (*Plugin) GetSchema

func (p *Plugin) GetSchema() (map[string]*proto.TableSchema, error)

func (*Plugin) Validate

func (p *Plugin) Validate() string

type PluginFunc

type PluginFunc func(context.Context) *Plugin

type QueryData

type QueryData struct {
	ConnectionManager *connection.Manager
	Table             *Table
	// if this is a get call (or a list call if list key columns are specified)
	// this will be populated with the quals as a map of column name to quals
	KeyColumnQuals map[string]*pb.QualValue
	// is this a get or a list
	FetchType    fetchType
	QueryContext *pb.QueryContext
	// contains filtered or unexported fields
}

func (*QueryData) SetFetchType

func (d *QueryData) SetFetchType(table *Table)

SetFetchType :: determine whether this is a get or a list call

func (*QueryData) StreamLeafListItem

func (d *QueryData) StreamLeafListItem(_ context.Context, item interface{})

func (*QueryData) StreamListItem

func (d *QueryData) StreamListItem(ctx context.Context, item interface{})

StreamListItem :: stream an item returned from the list call wrap in a rowData object

type RowData

type RowData struct {
	Item interface{}
	// contains filtered or unexported fields
}

func (*RowData) GetColumnData

func (r *RowData) GetColumnData(column *Column) (interface{}, error)

GetColumnData :: return the root item, and, if this column has a hydrate function registered, the associated hydrate data

type ServeOpts

type ServeOpts struct {
	PluginName string
	PluginFunc PluginFunc
}

ServeOpts are the configurations to serve a plugin.

type Table

type Table struct {
	Name string
	// table description
	Description string
	// column definitions
	Columns          []*Column
	List             *ListConfig
	Get              *GetConfig
	DefaultTransform *transform.ColumnTransforms
	// the parent plugin object
	Plugin *Plugin
	// definitions of dependencies between hydrate functions
	HydrateDependencies []HydrateDependencies
	HydrateConfig       []HydrateConfig
}

Table :: struct representing a plugin table

func (Table) GetSchema

func (t Table) GetSchema() *pb.TableSchema

func (*Table) SafeGet

func (t *Table) SafeGet() HydrateFunc

SafeGet :: higher order function which returns a GetFunc which handles NotFound errors

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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