package grafana import ( "context" "encoding/json" "fmt" "net/url" "time" ) type DashboardVersion struct { ID uint `json:"id"` DashboardID uint `json:"dashboardId"` ParentVersion uint `json:"parentVersion"` RestoredFrom uint `json:"restoredFrom"` Version uint `json:"version"` Created time.Time `json:"created"` CreatedBy string `json:"createdBy"` Message string `json:"message"` } func queryParams(params ...QueryParam) url.Values { u := url.URL{} q := u.Query() for _, p := range params { p(&q) } return q } func (c *Client) GetDashboardVersionsByDashboardID(ctx context.Context, dashboardID uint, params ...QueryParam) ([]DashboardVersion, error) { var ( raw []byte code int err error ) if raw, code, err = c.get(ctx, fmt.Sprintf("api/dashboards/id/%d/versions", dashboardID), queryParams(params...)); err != nil { return nil, err } if code != 200 { return nil, fmt.Errorf("HTTP error %d: returns %s", code, raw) } var versions []DashboardVersion err = json.Unmarshal(raw, &versions) return versions, err } func (c *Client) SearchDashboards(ctx context.Context, query string, starred bool, tags ...string) ([]FoundBoard, error) { params := []SearchParam{ SearchType(SearchTypeDashboard), SearchQuery(query), SearchStarred(starred), } for _, tag := range tags { params = append(params, SearchTag(tag)) } return c.Search(ctx, params...) }