Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enable = [
"exportloopref",
"staticcheck",
"structcheck",
#"stylecheck",
"stylecheck",
"typecheck",
"unconvert",
"unused",
Expand Down
4 changes: 2 additions & 2 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func (c *Client) CreateUser(user User) (int64, error) {
}

created := struct {
Id int64 `json:"id"`
ID int64 `json:"id"`
}{}

err = c.request("POST", "/api/admin/users", nil, bytes.NewBuffer(data), &created)
if err != nil {
return id, err
}

return created.Id, err
return created.ID, err
}

// DeleteUser deletes a Grafana user.
Expand Down
10 changes: 5 additions & 5 deletions alertnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

// AlertNotification represents a Grafana alert notification.
type AlertNotification struct {
Id int64 `json:"id,omitempty"`
Uid string `json:"uid"`
ID int64 `json:"id,omitempty"`
UID string `json:"uid"`
Name string `json:"name"`
Type string `json:"type"`
IsDefault bool `json:"isDefault"`
Expand Down Expand Up @@ -50,20 +50,20 @@ func (c *Client) NewAlertNotification(a *AlertNotification) (int64, error) {
return 0, err
}
result := struct {
Id int64 `json:"id"`
ID int64 `json:"id"`
}{}

err = c.request("POST", "/api/alert-notifications", nil, bytes.NewBuffer(data), &result)
if err != nil {
return 0, err
}

return result.Id, err
return result.ID, err
}

// UpdateAlertNotification updates a Grafana alert notification.
func (c *Client) UpdateAlertNotification(a *AlertNotification) error {
path := fmt.Sprintf("/api/alert-notifications/%d", a.Id)
path := fmt.Sprintf("/api/alert-notifications/%d", a.ID)
data, err := json.Marshal(a)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions alertnotification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestAlertNotifications(t *testing.T) {
if len(alertnotifications) != 1 {
t.Error("Length of returned alert notifications should be 1")
}
if alertnotifications[0].Id != 1 || alertnotifications[0].Name != "Team A" {
if alertnotifications[0].ID != 1 || alertnotifications[0].Name != "Team A" {
t.Error("Not correctly parsing returned alert notifications.")
}
}
Expand All @@ -106,7 +106,7 @@ func TestAlertNotification(t *testing.T) {

t.Log(pretty.PrettyFormat(resp))

if resp.Id != alertnotification || resp.Name != "Team A" {
if resp.ID != alertnotification || resp.Name != "Team A" {
t.Error("Not correctly parsing returned alert notification.")
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestUpdateAlertNotification(t *testing.T) {
defer server.Close()

an := &AlertNotification{
Id: 1,
ID: 1,
Name: "Team A",
Type: "email",
IsDefault: false,
Expand Down
38 changes: 13 additions & 25 deletions dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ type DashboardMeta struct {
// DashboardSaveResponse represents the Grafana API response to creating or saving a dashboard.
type DashboardSaveResponse struct {
Slug string `json:"slug"`
Id int64 `json:"id"`
Uid string `json:"uid"`
ID int64 `json:"id"`
UID string `json:"uid"`
Status string `json:"status"`
Version int64 `json:"version"`
}

// DashboardSearchResponse represents the Grafana API dashboard search response.
type DashboardSearchResponse struct {
Id uint `json:"id"`
Uid string `json:"uid"`
ID uint `json:"id"`
UID string `json:"uid"`
Title string `json:"title"`
Uri string `json:"uri"`
Url string `json:"url"`
URI string `json:"uri"`
URL string `json:"url"`
Slug string `json:"slug"`
Type string `json:"type"`
Tags []string `json:"tags"`
IsStarred bool `json:"isStarred"`
FolderId uint `json:"folderId"`
FolderUid string `json:"folderUid"`
FolderID uint `json:"folderId"`
FolderUID string `json:"folderUid"`
FolderTitle string `json:"folderTitle"`
FolderUrl string `json:"folderUrl"`
FolderURL string `json:"folderUrl"`
}

// Dashboard represents a Grafana dashboard.
Expand Down Expand Up @@ -100,19 +100,13 @@ func (c *Client) Dashboards() ([]DashboardSearchResponse, error) {
return dashboards, err
}

// DashboardByUid fetches and returns the dashboard whose UID is passed.
func (c *Client) DashboardByUid(uid string) (*Dashboard, error) {
return c.dashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
}

// Dashboard will be removed.
// Deprecated: Starting from Grafana v5.0. Use DashboardByUid instead.
// Deprecated: Starting from Grafana v5.0. Use DashboardByUID instead.
func (c *Client) Dashboard(slug string) (*Dashboard, error) {
return c.dashboard(fmt.Sprintf("/api/dashboards/db/%s", slug))
}

// DashboardByUID will be removed.
// Deprecated: Interface typo. Use DashboardByUid instead.
// DashboardByUID gets a dashboard by UID.
func (c *Client) DashboardByUID(uid string) (*Dashboard, error) {
return c.dashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
}
Expand All @@ -128,19 +122,13 @@ func (c *Client) dashboard(path string) (*Dashboard, error) {
return result, err
}

// DeleteDashboardByUid deletes the dashboard whose UID it's passed.
func (c *Client) DeleteDashboardByUid(uid string) error {
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
}

// DeleteDashboard will be removed.
// Deprecated: Starting from Grafana v5.0. Use DeleteDashboardByUid instead.
// Deprecated: Starting from Grafana v5.0. Use DeleteDashboardByUID instead.
func (c *Client) DeleteDashboard(slug string) error {
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/db/%s", slug))
}

// DeleteDashboardByUID will be removed.
// Deprecated: Interface typo. Use DeleteDashboardByUid instead.
// DeleteDashboardByUID deletes a dashboard by UID.
func (c *Client) DeleteDashboardByUID(uid string) error {
return c.deleteDashboard(fmt.Sprintf("/api/dashboards/uid/%s", uid))
}
Expand Down
14 changes: 7 additions & 7 deletions dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func TestDashboardCreateAndUpdate(t *testing.T) {

t.Log(pretty.PrettyFormat(resp))

if resp.Uid != "nErXDvCkzz" {
t.Errorf("Invalid uid - %s, Expected %s", resp.Uid, "nErXDvCkzz")
if resp.UID != "nErXDvCkzz" {
t.Errorf("Invalid uid - %s, Expected %s", resp.UID, "nErXDvCkzz")
}

for _, code := range []int{400, 401, 403, 412} {
Expand All @@ -89,7 +89,7 @@ func TestDashboardGet(t *testing.T) {
t.Errorf("Invalid uid - %s, Expected %s", uid, "cIBgcSjkk")
}

resp, err = client.DashboardByUid("cIBgcSjkk")
resp, err = client.DashboardByUID("cIBgcSjkk")
if err != nil {
t.Error(err)
}
Expand All @@ -105,7 +105,7 @@ func TestDashboardGet(t *testing.T) {
t.Errorf("%d not detected", code)
}

_, err = client.DashboardByUid("cIBgcSjkk")
_, err = client.DashboardByUID("cIBgcSjkk")
if err == nil {
t.Errorf("%d not detected", code)
}
Expand All @@ -121,7 +121,7 @@ func TestDashboardDelete(t *testing.T) {
t.Error(err)
}

err = client.DeleteDashboardByUid("cIBgcSjkk")
err = client.DeleteDashboardByUID("cIBgcSjkk")
if err != nil {
t.Error(err)
}
Expand All @@ -134,7 +134,7 @@ func TestDashboardDelete(t *testing.T) {
t.Errorf("%d not detected", code)
}

err = client.DeleteDashboardByUid("cIBgcSjkk")
err = client.DeleteDashboardByUID("cIBgcSjkk")
if err == nil {
t.Errorf("%d not detected", code)
}
Expand All @@ -156,7 +156,7 @@ func TestDashboards(t *testing.T) {
t.Error("Length of returned dashboards should be 1")
}

if dashboards[0].Id != 1 || dashboards[0].Title != "Grafana Stats" {
if dashboards[0].ID != 1 || dashboards[0].Title != "Grafana Stats" {
t.Error("Not correctly parsing returned dashboards.")
}
}
26 changes: 13 additions & 13 deletions datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// DataSource represents a Grafana data source.
type DataSource struct {
Id int64 `json:"id,omitempty"`
ID int64 `json:"id,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
Expand All @@ -19,7 +19,7 @@ type DataSource struct {
// Deprecated: Use secureJsonData.password instead.
Password string `json:"password,omitempty"`

OrgId int64 `json:"orgId,omitempty"`
OrgID int64 `json:"orgId,omitempty"`
IsDefault bool `json:"isDefault"`

BasicAuth bool `json:"basicAuth"`
Expand All @@ -34,9 +34,9 @@ type DataSource struct {
// JSONData is a representation of the datasource `jsonData` property
type JSONData struct {
// Used by all datasources
TlsAuth bool `json:"tlsAuth,omitempty"`
TlsAuthWithCACert bool `json:"tlsAuthWithCACert,omitempty"`
TlsSkipVerify bool `json:"tlsSkipVerify,omitempty"`
TLSAuth bool `json:"tlsAuth,omitempty"`
TLSAuthWithCACert bool `json:"tlsAuthWithCACert,omitempty"`
TLSSkipVerify bool `json:"tlsSkipVerify,omitempty"`

// Used by Graphite
GraphiteVersion string `json:"graphiteVersion,omitempty"`
Expand Down Expand Up @@ -75,22 +75,22 @@ type JSONData struct {
ConnMaxLifetime int64 `json:"connMaxLifetime,omitempty"`

// Used by Prometheus
HttpMethod string `json:"httpMethod,omitempty"`
HTTPMethod string `json:"httpMethod,omitempty"`
QueryTimeout string `json:"queryTimeout,omitempty"`

// Used by Stackdriver
AuthenticationType string `json:"authenticationType,omitempty"`
ClientEmail string `json:"clientEmail,omitempty"`
DefaultProject string `json:"defaultProject,omitempty"`
TokenUri string `json:"tokenUri,omitempty"`
TokenURI string `json:"tokenUri,omitempty"`
}

// SecureJSONData is a representation of the datasource `secureJsonData` property
type SecureJSONData struct {
// Used by all datasources
TlsCACert string `json:"tlsCACert,omitempty"`
TlsClientCert string `json:"tlsClientCert,omitempty"`
TlsClientKey string `json:"tlsClientKey,omitempty"`
TLSCACert string `json:"tlsCACert,omitempty"`
TLSClientCert string `json:"tlsClientCert,omitempty"`
TLSClientKey string `json:"tlsClientKey,omitempty"`
Password string `json:"password,omitempty"`
BasicAuthPassword string `json:"basicAuthPassword,omitempty"`

Expand All @@ -110,20 +110,20 @@ func (c *Client) NewDataSource(s *DataSource) (int64, error) {
}

result := struct {
Id int64 `json:"id"`
ID int64 `json:"id"`
}{}

err = c.request("POST", "/api/datasources", nil, bytes.NewBuffer(data), &result)
if err != nil {
return 0, err
}

return result.Id, err
return result.ID, err
}

// UpdateDataSource updates a Grafana data source.
func (c *Client) UpdateDataSource(s *DataSource) error {
path := fmt.Sprintf("/api/datasources/%d", s.Id)
path := fmt.Sprintf("/api/datasources/%d", s.ID)
data, err := json.Marshal(s)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestNewDataSource(t *testing.T) {
AuthType: "keys",
CustomMetricsNamespaces: "SomeNamespace",
DefaultRegion: "us-east-1",
TlsSkipVerify: true,
TLSSkipVerify: true,
},
SecureJSONData: SecureJSONData{
AccessKey: "123",
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestNewPrometheusDataSource(t *testing.T) {
Access: "access",
IsDefault: true,
JSONData: JSONData{
HttpMethod: "POST",
HTTPMethod: "POST",
QueryTimeout: "60s",
TimeInterval: "1m",
},
Expand Down
4 changes: 2 additions & 2 deletions folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

// Folder represents a Grafana folder.
type Folder struct {
Id int64 `json:"id"`
Uid string `json:"uid"`
ID int64 `json:"id"`
UID string `json:"uid"`
Title string `json:"title"`
}

Expand Down
18 changes: 9 additions & 9 deletions folder_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

// FolderPermission has information such as a folder, user, team, role and permission.
type FolderPermission struct {
Id int64 `json:"id"`
FolderUid string `json:"uid"`
UserId int64 `json:"userId"`
TeamId int64 `json:"teamId"`
ID int64 `json:"id"`
FolderUID string `json:"uid"`
UserID int64 `json:"userId"`
TeamID int64 `json:"teamId"`
Role string `json:"role"`
IsFolder bool `json:"isFolder"`

Expand All @@ -23,8 +23,8 @@ type FolderPermission struct {
PermissionName string `json:"permissionName"`

// optional fields
FolderId int64 `json:"folderId,omitempty"`
DashboardId int64 `json:"dashboardId,omitempty"`
FolderID int64 `json:"folderId,omitempty"`
DashboardID int64 `json:"dashboardId,omitempty"`
}

// PermissionItems represents Grafana folder permission items.
Expand All @@ -34,11 +34,11 @@ type PermissionItems struct {

// PermissionItem represents a Grafana folder permission item.
type PermissionItem struct {
// As you can see the docs, each item has a pair of [Role|TeamId|UserId] and Permission.
// As you can see the docs, each item has a pair of [Role|TeamID|UserID] and Permission.
// unnecessary fields are omitted.
Role string `json:"role,omitempty"`
TeamId int64 `json:"teamId,omitempty"`
UserId int64 `json:"userId,omitempty"`
TeamID int64 `json:"teamId,omitempty"`
UserID int64 `json:"userId,omitempty"`
Permission int64 `json:"permission"`
}

Expand Down
Loading