executor.go 761 B

123456789101112131415161718192021222324252627282930313233343536
  1. package tsdb
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/grafana/grafana/pkg/models"
  6. )
  7. type Executor interface {
  8. Execute(ctx context.Context, queries QuerySlice, query *QueryContext) *BatchResult
  9. }
  10. var registry map[string]GetExecutorFn
  11. type GetExecutorFn func(dsInfo *models.DataSource) (Executor, error)
  12. func init() {
  13. registry = make(map[string]GetExecutorFn)
  14. }
  15. func getExecutorFor(dsInfo *models.DataSource) (Executor, error) {
  16. if fn, exists := registry[dsInfo.Type]; exists {
  17. executor, err := fn(dsInfo)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return executor, nil
  22. }
  23. return nil, fmt.Errorf("Could not find executor for data source type: %s", dsInfo.Type)
  24. }
  25. func RegisterExecutor(pluginId string, fn GetExecutorFn) {
  26. registry[pluginId] = fn
  27. }