clean up pointer usage
parent
7d275b9551
commit
ffe9943212
|
@ -42,28 +42,28 @@ func (d *DashboardsStore) All(ctx context.Context) ([]chronograf.Dashboard, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add creates a new Dashboard in the DashboardsStore
|
// Add creates a new Dashboard in the DashboardsStore
|
||||||
func (d *DashboardsStore) Add(ctx context.Context, src *chronograf.Dashboard) (*chronograf.Dashboard, error) {
|
func (d *DashboardsStore) Add(ctx context.Context, src chronograf.Dashboard) (chronograf.Dashboard, error) {
|
||||||
if err := d.client.db.Update(func(tx *bolt.Tx) error {
|
if err := d.client.db.Update(func(tx *bolt.Tx) error {
|
||||||
b := tx.Bucket(DashboardBucket)
|
b := tx.Bucket(DashboardBucket)
|
||||||
id, _ := b.NextSequence()
|
id, _ := b.NextSequence()
|
||||||
|
|
||||||
src.ID = chronograf.DashboardID(id)
|
src.ID = chronograf.DashboardID(id)
|
||||||
strID := strconv.Itoa(int(id))
|
strID := strconv.Itoa(int(id))
|
||||||
if v, err := internal.MarshalDashboard(*src); err != nil {
|
if v, err := internal.MarshalDashboard(src); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err := b.Put([]byte(strID), v); err != nil {
|
} else if err := b.Put([]byte(strID), v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return &chronograf.Dashboard{}, err
|
return chronograf.Dashboard{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return src, nil
|
return src, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns a Dashboard if the id exists.
|
// Get returns a Dashboard if the id exists.
|
||||||
func (d *DashboardsStore) Get(ctx context.Context, id chronograf.DashboardID) (*chronograf.Dashboard, error) {
|
func (d *DashboardsStore) Get(ctx context.Context, id chronograf.DashboardID) (chronograf.Dashboard, error) {
|
||||||
var src chronograf.Dashboard
|
var src chronograf.Dashboard
|
||||||
if err := d.client.db.View(func(tx *bolt.Tx) error {
|
if err := d.client.db.View(func(tx *bolt.Tx) error {
|
||||||
strID := strconv.Itoa(int(id))
|
strID := strconv.Itoa(int(id))
|
||||||
|
@ -74,14 +74,14 @@ func (d *DashboardsStore) Get(ctx context.Context, id chronograf.DashboardID) (*
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return &chronograf.Dashboard{}, err
|
return chronograf.Dashboard{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &src, nil
|
return src, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the dashboard from DashboardsStore
|
// Delete the dashboard from DashboardsStore
|
||||||
func (s *DashboardsStore) Delete(ctx context.Context, d *chronograf.Dashboard) error {
|
func (s *DashboardsStore) Delete(ctx context.Context, d chronograf.Dashboard) error {
|
||||||
if err := s.client.db.Update(func(tx *bolt.Tx) error {
|
if err := s.client.db.Update(func(tx *bolt.Tx) error {
|
||||||
if err := tx.Bucket(DashboardBucket).Delete(itob(int(d.ID))); err != nil {
|
if err := tx.Bucket(DashboardBucket).Delete(itob(int(d.ID))); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -95,7 +95,7 @@ func (s *DashboardsStore) Delete(ctx context.Context, d *chronograf.Dashboard) e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the dashboard in DashboardsStore
|
// Update the dashboard in DashboardsStore
|
||||||
func (s *DashboardsStore) Update(ctx context.Context, d *chronograf.Dashboard) error {
|
func (s *DashboardsStore) Update(ctx context.Context, d chronograf.Dashboard) error {
|
||||||
if err := s.client.db.Update(func(tx *bolt.Tx) error {
|
if err := s.client.db.Update(func(tx *bolt.Tx) error {
|
||||||
// Get an existing dashboard with the same ID.
|
// Get an existing dashboard with the same ID.
|
||||||
b := tx.Bucket(DashboardBucket)
|
b := tx.Bucket(DashboardBucket)
|
||||||
|
@ -104,7 +104,7 @@ func (s *DashboardsStore) Update(ctx context.Context, d *chronograf.Dashboard) e
|
||||||
return chronograf.ErrDashboardNotFound
|
return chronograf.ErrDashboardNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := internal.MarshalDashboard(*d); err != nil {
|
if v, err := internal.MarshalDashboard(d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err := b.Put([]byte(strID), v); err != nil {
|
} else if err := b.Put([]byte(strID), v); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -250,13 +250,13 @@ type DashboardsStore interface {
|
||||||
// All lists all dashboards from the DashboardStore
|
// All lists all dashboards from the DashboardStore
|
||||||
All(context.Context) ([]Dashboard, error)
|
All(context.Context) ([]Dashboard, error)
|
||||||
// Create a new Dashboard in the DashboardStore
|
// Create a new Dashboard in the DashboardStore
|
||||||
Add(context.Context, *Dashboard) (*Dashboard, error)
|
Add(context.Context, Dashboard) (Dashboard, error)
|
||||||
// Delete the Dashboard from the DashboardStore if `ID` exists.
|
// Delete the Dashboard from the DashboardStore if `ID` exists.
|
||||||
Delete(context.Context, *Dashboard) error
|
Delete(context.Context, Dashboard) error
|
||||||
// Get retrieves a dashboard if `ID` exists.
|
// Get retrieves a dashboard if `ID` exists.
|
||||||
Get(ctx context.Context, id DashboardID) (*Dashboard, error)
|
Get(ctx context.Context, id DashboardID) (Dashboard, error)
|
||||||
// Update replaces the dashboard information
|
// Update replaces the dashboard information
|
||||||
Update(context.Context, *Dashboard) error
|
Update(context.Context, Dashboard) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExplorationID is a unique ID for an Exploration.
|
// ExplorationID is a unique ID for an Exploration.
|
||||||
|
|
|
@ -68,14 +68,14 @@ func (s *Service) DashboardID(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res := newDashboardResponse(*e)
|
res := newDashboardResponse(e)
|
||||||
encodeJSON(w, http.StatusOK, res, s.Logger)
|
encodeJSON(w, http.StatusOK, res, s.Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDashboard creates and returns a new dashboard object
|
// NewDashboard creates and returns a new dashboard object
|
||||||
func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
|
func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
var dashboard *chronograf.Dashboard
|
var dashboard chronograf.Dashboard
|
||||||
if err := json.NewDecoder(r.Body).Decode(&dashboard); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(dashboard); err != nil {
|
||||||
invalidJSON(w, s.Logger)
|
invalidJSON(w, s.Logger)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res := newDashboardResponse(*dashboard)
|
res := newDashboardResponse(dashboard)
|
||||||
w.Header().Add("Location", res.Links.Self)
|
w.Header().Add("Location", res.Links.Self)
|
||||||
encodeJSON(w, http.StatusCreated, res, s.Logger)
|
encodeJSON(w, http.StatusCreated, res, s.Logger)
|
||||||
}
|
}
|
||||||
|
@ -135,14 +135,14 @@ func (s *Service) UpdateDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var req *chronograf.Dashboard
|
var req chronograf.Dashboard
|
||||||
if err := json.NewDecoder(r.Body).Decode(req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(req); err != nil {
|
||||||
invalidJSON(w, s.Logger)
|
invalidJSON(w, s.Logger)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.ID = id
|
req.ID = id
|
||||||
|
|
||||||
if err := ValidDashboardRequest(dashboard); err != nil {
|
if err := ValidDashboardRequest(req); err != nil {
|
||||||
invalidData(w, err, s.Logger)
|
invalidData(w, err, s.Logger)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func (s *Service) UpdateDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res := newDashboardResponse(*req)
|
res := newDashboardResponse(req)
|
||||||
encodeJSON(w, http.StatusOK, res, s.Logger)
|
encodeJSON(w, http.StatusOK, res, s.Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ func ValidDashboardRequest(d chronograf.Dashboard) error {
|
||||||
for _, c := range d.Cells {
|
for _, c := range d.Cells {
|
||||||
for _, q := range c.Queries {
|
for _, q := range c.Queries {
|
||||||
if len(q) == 0 {
|
if len(q) == 0 {
|
||||||
return ftm.Errorf("query required")
|
return fmt.Errorf("query required")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue