query_endpoint.go 846 B

123456789101112131415161718192021222324252627282930313233343536
  1. package tsdb
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/grafana/grafana/pkg/models"
  6. )
  7. type TsdbQueryEndpoint interface {
  8. Query(ctx context.Context, ds *models.DataSource, query *TsdbQuery) (*Response, error)
  9. }
  10. var registry map[string]GetTsdbQueryEndpointFn
  11. type GetTsdbQueryEndpointFn func(dsInfo *models.DataSource) (TsdbQueryEndpoint, error)
  12. func init() {
  13. registry = make(map[string]GetTsdbQueryEndpointFn)
  14. }
  15. func getTsdbQueryEndpointFor(dsInfo *models.DataSource) (TsdbQueryEndpoint, 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 RegisterTsdbQueryEndpoint(pluginId string, fn GetTsdbQueryEndpointFn) {
  26. registry[pluginId] = fn
  27. }