Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidQueryRunnerSignature = errors.New("queryRunner must have 3 input params") ErrQueryRunnerIsNotAFunction = errors.New("queryRunner is not a function") ErrFirstArgHasInvalidType = errors.New("first input argument must have context.Context type") ErrSecondArgHasInvalidType = errors.New("second input argument must be a struct") ErrThirdArgHasInvalidType = errors.New("third input argument must be a pointer to a struct") )
Guard errors
var ErrNotFound = errors.New("query runner not found")
ErrNotFound indicates that the query runner was not registered for the given query.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher dispatches the given query to a pre-registered query runner.
func NewDispatcher ¶
func NewDispatcher() *Dispatcher
NewDispatcher creates a new instance of Dispatcher.
func (*Dispatcher) RegisterQueryRunner ¶
func (d *Dispatcher) RegisterQueryRunner(queryRunnerFnName string, queryRunnerFn QueryRunnerFn)
RegisterQueryRunner registers a query runner. TODO: add guards for an empty runner name and a nil runner.
type QueryRunner ¶
type QueryRunner interface {
RunQuery(ctx context.Context, query interface{}, report interface{}) error
}
QueryRunner runs a query and returns the corresponding result setting report value by ref.
type QueryRunnerFn ¶
QueryRunnerFn defines a query runner signature.
func Adapt ¶
func Adapt(queryRunner interface{}) (QueryRunnerFn, error)
Adapt transforms a concrete query runner into a generic one. A concrete runner function should have 3 arguments: - ctx context.Context, - q - a query struct, - r - a pointer to a report struct.
The returned param must have error type. An example signature may look like:
func(ctx context.Context, q TestQuery, r *TestReport) error
func MustAdapt ¶
func MustAdapt(queryRunner interface{}) QueryRunnerFn
MustAdapt acts Like Adapt, but panics on error.