forked from nytm/go-grafana-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.go
65 lines (53 loc) · 1.38 KB
/
admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gapi
import (
"fmt"
)
// AdminCreateUserForm is used to create a new user
type AdminCreateUserForm struct {
Email string `json:"email"`
Login string `json:"login"`
Name string `json:"name"`
Password string `json:"password" binding:"Required"`
}
// CreateUserForm will create a user from the given form
func (c *Client) CreateUserForm(settings AdminCreateUserForm) error {
res, err := c.doJSONRequest("POST", "/api/admin/users", settings)
if err != nil {
return err
}
return res.Error()
}
// DeleteUser deletes the user with the given ID from Grafana
func (c *Client) DeleteUser(id int64) error {
res, err := c.doRequest("DELETE", fmt.Sprintf("/api/admin/users/%d", id), nil)
if err != nil {
return err
}
return res.Error()
}
// Stats will get the stats from the API
func (c *Client) Stats() (map[string]int64, error) {
v := map[string]int64{}
res, err := c.doRequest("GET", "/api/admin/stats", nil)
if err != nil {
return v, err
}
if !res.OK() {
return v, res.Error()
}
err = res.BindJSON(&v)
return v, err
}
// FrontEndSettings will get the front end settings from the API
func (c *Client) FrontEndSettings() (map[string]interface{}, error) {
v := map[string]interface{}{}
res, err := c.doRequest("GET", "/api/frontend/settings", nil)
if err != nil {
return v, err
}
if !res.OK() {
return v, res.Error()
}
err = res.BindJSON(&v)
return v, err
}