entitysource

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheQuerier

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

func NewCacheQuerier

func NewCacheQuerier(entities map[EntityID]Entity) *CacheQuerier

func (CacheQuerier) Filter

func (c CacheQuerier) Filter(_ context.Context, filter Predicate) (EntityList, error)

func (CacheQuerier) Get

func (c CacheQuerier) Get(_ context.Context, id EntityID) *Entity

func (CacheQuerier) GroupBy

func (CacheQuerier) Iterate

type Entity

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

func NewEntity

func NewEntity(id EntityID, properties map[string]string) *Entity

func (*Entity) GetProperty

func (e *Entity) GetProperty(key string) (string, error)

func (*Entity) ID

func (e *Entity) ID() EntityID

type EntityContentGetter

type EntityContentGetter interface {
	GetContent(ctx context.Context, id EntityID) (interface{}, error)
}

EntityContentGetter is used to retrieve arbitrary content linked to the entities. For instance, the actual package to install, etc.

type EntityID

type EntityID string

type EntityList

type EntityList []Entity

func (EntityList) CollectIds

func (r EntityList) CollectIds() []EntityID

func (EntityList) Sort

func (r EntityList) Sort(fn SortFunction) EntityList

type EntityListMap

type EntityListMap map[string]EntityList

func (EntityListMap) Sort

type EntityPropertyNotFoundError

type EntityPropertyNotFoundError string

func (EntityPropertyNotFoundError) Error

type EntityQuerier

type EntityQuerier interface {
	Get(ctx context.Context, id EntityID) *Entity
	Filter(ctx context.Context, filter Predicate) (EntityList, error)
	GroupBy(ctx context.Context, fn GroupByFunction) (EntityListMap, error)
	Iterate(ctx context.Context, fn IteratorFunction) error
}

EntityQuerier is an interface for querying entities in some store

type EntitySource

type EntitySource interface {
	EntityQuerier
	EntityContentGetter
}

EntitySource provides a query and content acquisition interface for arbitrary entity stores

type Group

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

Group is a simple EntitySource implementation which groups various entity sources to provide a single interface by which to query them and get content

func NewGroup

func NewGroup(entitySources ...EntitySource) *Group

func (*Group) Filter

func (g *Group) Filter(ctx context.Context, filter Predicate) (EntityList, error)

func (*Group) Get

func (g *Group) Get(ctx context.Context, id EntityID) *Entity

func (*Group) GetContent

func (g *Group) GetContent(ctx context.Context, id EntityID) (interface{}, error)

func (*Group) GroupBy

func (g *Group) GroupBy(ctx context.Context, fn GroupByFunction) (EntityListMap, error)

func (*Group) Iterate

func (g *Group) Iterate(ctx context.Context, fn IteratorFunction) error

type GroupByFunction

type GroupByFunction func(e1 *Entity) []string

GroupByFunction transforms an entity into a slice of keys (strings) over which the entities will be grouped by

type IteratorFunction

type IteratorFunction func(entity *Entity) error

IteratorFunction is executed for each entity when iterating over all entities

type NoContentSource

type NoContentSource struct{}

func (*NoContentSource) GetContent

func (n *NoContentSource) GetContent(_ context.Context, _ EntityID) (interface{}, error)

type Predicate

type Predicate func(entity *Entity) bool

Predicate returns true if the entity should be kept when filtering

func And

func And(predicates ...Predicate) Predicate

func Not

func Not(predicate Predicate) Predicate

func Or

func Or(predicates ...Predicate) Predicate

type SortFunction

type SortFunction func(e1 *Entity, e2 *Entity) bool

SortFunction returns true if e1 is less than e2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳