add marshal/unmarshal for dashboards

pull/10616/head
Jade McGough 2016-12-13 02:25:26 -08:00
parent 9ba8820c42
commit 76fb9a95c4
1 changed files with 32 additions and 1 deletions

View File

@ -188,12 +188,43 @@ func UnmarshalLayout(data []byte, l *chronograf.Layout) error {
return nil return nil
} }
// MarshalDashboard encodes a dashboard to binary protobuf format.
func MarshalDashboard(d chronograf.Dashboard) ([]byte, error) { func MarshalDashboard(d chronograf.Dashboard) ([]byte, error) {
return proto.Marshal(&Dashboard{ cells := make([]*DashboardCell, len(l.Cells))
for i, c := range l.Cells {
cells[i] = &DashboardCell{
X: c.X,
Y: c.Y,
W: c.W,
H: c.H,
Name: c.Name,
Queries: c.Queries,
Type: c.Type,
}
}
return proto.Marshal(&Dashboard{
ID: d.ID,
Cells: cells,
Name: d.Name,
}) })
} }
// UnmarshalDashboard decodes a layout from binary protobuf data.
func UnmarshalDashboard(data []byte, d *chonograf.Dashboard) error {
var pb Dashboard
if err := proto.Unmarshal(data, &pb); err != nil {
return err
}
d.ID = pb.ID
d.Cells = pb.Cells
d.Name = pb.Name
return nil
}
// ScopedAlert contains the source and the kapacitor id // ScopedAlert contains the source and the kapacitor id
type ScopedAlert struct { type ScopedAlert struct {
chronograf.AlertRule chronograf.AlertRule