diff --git a/bolt/dashboards.go b/bolt/dashboards.go index 8bf58b583..4df9ebf8e 100644 --- a/bolt/dashboards.go +++ b/bolt/dashboards.go @@ -42,28 +42,28 @@ func (d *DashboardsStore) All(ctx context.Context) ([]chronograf.Dashboard, erro } // 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 { b := tx.Bucket(DashboardBucket) id, _ := b.NextSequence() src.ID = chronograf.DashboardID(id) strID := strconv.Itoa(int(id)) - if v, err := internal.MarshalDashboard(*src); err != nil { + if v, err := internal.MarshalDashboard(src); err != nil { return err } else if err := b.Put([]byte(strID), v); err != nil { return err } return nil }); err != nil { - return &chronograf.Dashboard{}, err + return chronograf.Dashboard{}, err } return src, nil } // 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 if err := d.client.db.View(func(tx *bolt.Tx) error { strID := strconv.Itoa(int(id)) @@ -74,14 +74,14 @@ func (d *DashboardsStore) Get(ctx context.Context, id chronograf.DashboardID) (* } return nil }); err != nil { - return &chronograf.Dashboard{}, err + return chronograf.Dashboard{}, err } - return &src, nil + return src, nil } // 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 := tx.Bucket(DashboardBucket).Delete(itob(int(d.ID))); err != nil { return err @@ -95,7 +95,7 @@ func (s *DashboardsStore) Delete(ctx context.Context, d *chronograf.Dashboard) e } // 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 { // Get an existing dashboard with the same ID. b := tx.Bucket(DashboardBucket) @@ -104,7 +104,7 @@ func (s *DashboardsStore) Update(ctx context.Context, d *chronograf.Dashboard) e return chronograf.ErrDashboardNotFound } - if v, err := internal.MarshalDashboard(*d); err != nil { + if v, err := internal.MarshalDashboard(d); err != nil { return err } else if err := b.Put([]byte(strID), v); err != nil { return err diff --git a/chronograf.go b/chronograf.go index 0c8c3a29b..d26613205 100644 --- a/chronograf.go +++ b/chronograf.go @@ -250,13 +250,13 @@ type DashboardsStore interface { // All lists all dashboards from the DashboardStore All(context.Context) ([]Dashboard, error) // 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(context.Context, *Dashboard) error + Delete(context.Context, Dashboard) error // 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(context.Context, *Dashboard) error + Update(context.Context, Dashboard) error } // ExplorationID is a unique ID for an Exploration. diff --git a/server/dashboards.go b/server/dashboards.go index 96aa43c9a..8d792b43b 100644 --- a/server/dashboards.go +++ b/server/dashboards.go @@ -68,14 +68,14 @@ func (s *Service) DashboardID(w http.ResponseWriter, r *http.Request) { return } - res := newDashboardResponse(*e) + res := newDashboardResponse(e) encodeJSON(w, http.StatusOK, res, s.Logger) } // NewDashboard creates and returns a new dashboard object func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) { - var dashboard *chronograf.Dashboard - if err := json.NewDecoder(r.Body).Decode(&dashboard); err != nil { + var dashboard chronograf.Dashboard + if err := json.NewDecoder(r.Body).Decode(dashboard); err != nil { invalidJSON(w, s.Logger) return } @@ -92,7 +92,7 @@ func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) { return } - res := newDashboardResponse(*dashboard) + res := newDashboardResponse(dashboard) w.Header().Add("Location", res.Links.Self) encodeJSON(w, http.StatusCreated, res, s.Logger) } @@ -135,14 +135,14 @@ func (s *Service) UpdateDashboard(w http.ResponseWriter, r *http.Request) { return } - var req *chronograf.Dashboard + var req chronograf.Dashboard if err := json.NewDecoder(r.Body).Decode(req); err != nil { invalidJSON(w, s.Logger) return } req.ID = id - if err := ValidDashboardRequest(dashboard); err != nil { + if err := ValidDashboardRequest(req); err != nil { invalidData(w, err, s.Logger) return } @@ -153,7 +153,7 @@ func (s *Service) UpdateDashboard(w http.ResponseWriter, r *http.Request) { return } - res := newDashboardResponse(*req) + res := newDashboardResponse(req) encodeJSON(w, http.StatusOK, res, s.Logger) } @@ -166,7 +166,7 @@ func ValidDashboardRequest(d chronograf.Dashboard) error { for _, c := range d.Cells { for _, q := range c.Queries { if len(q) == 0 { - return ftm.Errorf("query required") + return fmt.Errorf("query required") } } }