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
|
||||
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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue