Documentation
¶
Index ¶
- Constants
- type Bus
- func (bus *Bus) CacheAdapters(adps ...CacheAdapter)
- func (bus *Bus) ErrorHandlers(hdls ...ErrorHandler)
- func (bus *Bus) Handlers(hdls ...Handler)
- func (bus *Bus) InitializeIteratorHandlers(hdls ...IteratorHandler)
- func (bus *Bus) IteratorQuery(qry Query) (*IteratorResult, error)
- func (bus *Bus) IteratorQueueBuffer(buf int)
- func (bus *Bus) IteratorResultBuffer(buf int)
- func (bus *Bus) IteratorWorkerPoolSize(workerPoolSize int)
- func (bus *Bus) Query(qry Query) (*Result, error)
- func (bus *Bus) Shutdown()
- type CacheAdapter
- type Cacheable
- type ErrorBusIsShuttingDown
- type ErrorBusNotInitialized
- type ErrorHandler
- type ErrorInvalidQuery
- type ErrorNoQueryHandlersFound
- type ErrorQueryTimedOut
- type Handler
- type IteratorHandler
- type IteratorResult
- type MemoryCacheAdapter
- type Query
- type Result
- func (res *Result) Add(data interface{})
- func (res *Result) All() []interface{}
- func (res *Result) CacheKey() []byte
- func (res *Result) CachedAt() time.Time
- func (res *Result) Done()
- func (res *Result) ExpiresAt() time.Time
- func (res *Result) First() interface{}
- func (res *Result) Handled()
- func (res *Result) IsCached() bool
- func (res *Result) IsFresh() bool
- func (res *Result) Set(data []interface{})
Constants ¶
const ( // InvalidQueryError is a constant equivalent of the ErrorInvalidQuery error. InvalidQueryError = ErrorInvalidQuery("query: invalid query") // BusNotInitializedError is a constant equivalent of the ErrorBusNotInitialized error. BusNotInitializedError = ErrorBusNotInitialized("query: the bus is not initialized") // BusIsShuttingDownError is a constant equivalent of the ErrorBusIsShuttingDown error. BusIsShuttingDownError = ErrorBusIsShuttingDown("query: the bus is shutting down") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is the only struct exported and required for the query bus usage. The Bus should be instantiated using the NewBus function.
func NewBus ¶
func NewBus() *Bus
NewBus instantiates the Bus struct. The Initialization of IteratorHandlers is performed separately (InitializeIteratorHandlers function) for dependency injection purposes.
func (*Bus) CacheAdapters ¶
func (bus *Bus) CacheAdapters(adps ...CacheAdapter)
CacheAdapters may optionally be provided. They will be used instead of the default MemoryCacheAdapter.
func (*Bus) ErrorHandlers ¶
func (bus *Bus) ErrorHandlers(hdls ...ErrorHandler)
ErrorHandlers may optionally be provided. They will receive any error thrown during the querying process.
func (*Bus) InitializeIteratorHandlers ¶
func (bus *Bus) InitializeIteratorHandlers(hdls ...IteratorHandler)
InitializeIteratorHandlers initializes the query bus to support iterator queries.
func (*Bus) IteratorQuery ¶
func (bus *Bus) IteratorQuery(qry Query) (*IteratorResult, error)
IteratorQuery uses a channel to iterate the results while they are being populated. *Iterator queries are not cached*.
func (*Bus) IteratorQueueBuffer ¶
IteratorQueueBuffer may optionally be provided to tweak the buffer size of the iterator query queue. This value may have high impact on performance depending on the use case. It can only be adjusted *before* the bus is initialized. It defaults to 100.
func (*Bus) IteratorResultBuffer ¶
IteratorResultBuffer may optionally be provided to tweak the buffer size of the results channel for iterator queries. This value may have high impact on performance depending on the use case. It defaults to 1.
func (*Bus) IteratorWorkerPoolSize ¶
IteratorWorkerPoolSize may optionally be provided to tweak the iteratorWorker pool size for iterator query queue. It can only be adjusted *before* the bus is initialized. It defaults to the value returned by runtime.GOMAXPROCS(0).
type CacheAdapter ¶
type CacheAdapter interface {
Set(qry Cacheable, res *Result) bool
Get(qry Cacheable) *Result
Expire(qry Cacheable)
Shutdown()
}
CacheAdapter must be implemented for a type to qualify as a cache adapter.
type ErrorBusIsShuttingDown ¶
type ErrorBusIsShuttingDown string
ErrorBusIsShuttingDown is used when queries are handled but the bus is shutting down.
func (ErrorBusIsShuttingDown) Error ¶
func (e ErrorBusIsShuttingDown) Error() string
Error returns the string message of ErrorBusIsShuttingDown.
type ErrorBusNotInitialized ¶
type ErrorBusNotInitialized string
ErrorBusNotInitialized is used when queries are handled but the bus is not initialized.
func (ErrorBusNotInitialized) Error ¶
func (e ErrorBusNotInitialized) Error() string
Error returns the string message of ErrorBusNotInitialized.
type ErrorHandler ¶
ErrorHandler must be implemented for a type to qualify as an error handler.
type ErrorInvalidQuery ¶
type ErrorInvalidQuery string
ErrorInvalidQuery is used when invalid queries are handled.
func (ErrorInvalidQuery) Error ¶
func (e ErrorInvalidQuery) Error() string
Error returns the string message of ErrorInvalidQuery.
type ErrorNoQueryHandlersFound ¶
type ErrorNoQueryHandlersFound struct {
// contains filtered or unexported fields
}
ErrorNoQueryHandlersFound is used when not a single handler is found for a specific query.
func NewErrorNoQueryHandlersFound ¶
func NewErrorNoQueryHandlersFound(query Query) ErrorNoQueryHandlersFound
NewErrorNoQueryHandlersFound creates a new ErrorNoQueryHandlersFound.
func (ErrorNoQueryHandlersFound) Error ¶
func (e ErrorNoQueryHandlersFound) Error() string
Error returns the string message of ErrorNoQueryHandlersFound.
type ErrorQueryTimedOut ¶
type ErrorQueryTimedOut struct {
// contains filtered or unexported fields
}
ErrorQueryTimedOut is used when the handling of a query times out.
func NewErrorQueryTimedOut ¶
func NewErrorQueryTimedOut(query Query) ErrorQueryTimedOut
NewErrorQueryTimedOut creates a new ErrorQueryTimedOut.
func (ErrorQueryTimedOut) Error ¶
func (e ErrorQueryTimedOut) Error() string
Error returns the string message of ErrorQueryTimedOut.
type IteratorHandler ¶
type IteratorHandler interface {
Handle(qry Query, res *IteratorResult) error
}
IteratorHandler must be implemented for a type to qualify as an iterator query handler.
type IteratorResult ¶
type IteratorResult struct {
// contains filtered or unexported fields
}
IteratorResult is the struct returned from iterator queries.
func (*IteratorResult) Done ¶
func (res *IteratorResult) Done()
Done explicitly marks this result as handled and final. Meaning it will not be propagated to other handlers.
func (*IteratorResult) Handled ¶
func (res *IteratorResult) Handled()
Handled explicitly marks this result as handled (so no error is thrown if no data is found)
func (*IteratorResult) IsCached ¶
func (res *IteratorResult) IsCached() bool
IsCached can be used to verify if this result was retrieved from cache.
func (*IteratorResult) IsFresh ¶
func (res *IteratorResult) IsFresh() bool
IsFresh can be used to verify if this result is fresh.
func (*IteratorResult) Iterate ¶
func (res *IteratorResult) Iterate() <-chan interface{}
Iterate is used to process the values that are being yielded
func (*IteratorResult) Yield ¶
func (res *IteratorResult) Yield(data interface{})
Yield is used to provide values while they are being processed
type MemoryCacheAdapter ¶
MemoryCacheAdapter is the struct used for memory caching purposes.
func NewMemoryCacheAdapter ¶
func NewMemoryCacheAdapter() *MemoryCacheAdapter
NewMemoryCacheAdapter initializes a new *MemoryCacheAdapter. This function will also initialize the respective cleaner routine.
func (*MemoryCacheAdapter) Expire ¶
func (ad *MemoryCacheAdapter) Expire(qry Cacheable)
Expire can optionally be used to forcibly expire a query cache.
func (*MemoryCacheAdapter) Get ¶
func (ad *MemoryCacheAdapter) Get(qry Cacheable) *Result
Get retrieves the cached result for the provided query.
func (*MemoryCacheAdapter) Set ¶
func (ad *MemoryCacheAdapter) Set(qry Cacheable, res *Result) bool
Set stores the cache value for the given query.
func (*MemoryCacheAdapter) Shutdown ¶
func (ad *MemoryCacheAdapter) Shutdown()
Shutdown is used to stop the cleaner routine.
type Query ¶
type Query interface {
ID() []byte
}
Query is the interface that must be implemented by any type to be considered a query.
type Result ¶
Result is the struct returned from regular queries.
func (*Result) Done ¶
func (res *Result) Done()
Done explicitly marks this result as handled and final. Meaning it will not be propagated to other handlers.
func (*Result) First ¶
func (res *Result) First() interface{}
First returns the first value of the data slice
func (*Result) Handled ¶
func (res *Result) Handled()
Handled explicitly marks this result as handled (so no error is thrown if no data is found)
func (*Result) IsCached ¶
func (res *Result) IsCached() bool
IsCached can be used to verify if this result was retrieved from cache.