mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 17:22:18 +08:00
34 lines
650 B
Go
34 lines
650 B
Go
package api
|
|
|
|
import (
|
|
"github.com/torkelo/grafana-pro/pkg/bus"
|
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
|
m "github.com/torkelo/grafana-pro/pkg/models"
|
|
)
|
|
|
|
func GetDataSources(c *middleware.Context) {
|
|
query := m.GetDataSourcesQuery{AccountId: c.Account.Id}
|
|
err := bus.Dispatch(&query)
|
|
|
|
if err != nil {
|
|
c.JsonApiErr(500, "Failed to query datasources", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
func AddDataSource(c *middleware.Context) {
|
|
cmd := m.AddDataSourceCommand{}
|
|
|
|
if !c.JsonBody(&cmd) {
|
|
c.JsonApiErr(400, "bad request", nil)
|
|
return
|
|
}
|
|
|
|
err := bus.Dispatch(&cmd)
|
|
if err != nil {
|
|
c.JsonApiErr(500, "Failed to add datasource", err)
|
|
return
|
|
}
|
|
|
|
}
|