forked from nytm/go-grafana-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
50 lines (42 loc) · 1.19 KB
/
user.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
package gapi
import (
"net/url"
)
// User represents a Grafana user.
type User struct {
Id int64 `json:"id,omitempty"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
Login string `json:"login,omitempty"`
Password string `json:"password,omitempty"`
IsAdmin bool `json:"isAdmin,omitempty"`
}
// Users fetches and returns Grafana users.
func (c *Client) Users() ([]User, error) {
users := make([]User, 0)
err := c.request("GET", "/api/users", nil, nil, &users)
if err != nil {
return users, err
}
return users, err
}
// UserByEmail fetches and returns the user whose email matches that passed.
func (c *Client) UserByEmail(email string) (User, error) {
user := User{}
query := url.Values{}
query.Add("loginOrEmail", email)
tmp := struct {
Id int64 `json:"id,omitempty"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
Login string `json:"login,omitempty"`
Password string `json:"password,omitempty"`
IsAdmin bool `json:"isGrafanaAdmin,omitempty"`
}{}
err := c.request("GET", "/api/users/lookup", query, nil, &tmp)
if err != nil {
return user, err
}
user = User(tmp)
return user, err
}