add marshal/unmarshal for dashboards
parent
9ba8820c42
commit
76fb9a95c4
|
@ -188,12 +188,43 @@ func UnmarshalLayout(data []byte, l *chronograf.Layout) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// MarshalDashboard encodes a dashboard to binary protobuf format.
|
||||
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
|
||||
type ScopedAlert struct {
|
||||
chronograf.AlertRule
|
||||
|
|
Loading…
Reference in New Issue