api_datasources.go 650 B

123456789101112131415161718192021222324252627282930313233
  1. package api
  2. import (
  3. "github.com/torkelo/grafana-pro/pkg/bus"
  4. "github.com/torkelo/grafana-pro/pkg/middleware"
  5. m "github.com/torkelo/grafana-pro/pkg/models"
  6. )
  7. func GetDataSources(c *middleware.Context) {
  8. query := m.GetDataSourcesQuery{AccountId: c.Account.Id}
  9. err := bus.Dispatch(&query)
  10. if err != nil {
  11. c.JsonApiErr(500, "Failed to query datasources", err)
  12. return
  13. }
  14. }
  15. func AddDataSource(c *middleware.Context) {
  16. cmd := m.AddDataSourceCommand{}
  17. if !c.JsonBody(&cmd) {
  18. c.JsonApiErr(400, "bad request", nil)
  19. return
  20. }
  21. err := bus.Dispatch(&cmd)
  22. if err != nil {
  23. c.JsonApiErr(500, "Failed to add datasource", err)
  24. return
  25. }
  26. }