Blob


1 package icinga
3 import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "net/http"
8 )
10 type User struct {
11 Name string
12 Type string
13 Attrs struct {
14 Email string
15 }
16 }
18 var testUser = User{
19 Name: "Olly",
20 Type: "User",
21 Attrs: struct {
22 Email string
23 }{Email: "olly@example.com"},
24 }
26 func (c *Client) Users() ([]User, error) {
27 resp, err := c.get("/objects/users")
28 if err != nil {
29 return nil, err
30 }
31 if resp.StatusCode != http.StatusOK {
32 return nil, fmt.Errorf("get /objects/users: status %s", resp.Status)
33 }
34 return []User{testUser}, nil
35 }
37 func (c *Client) CreateUser(name, email string) error {
38 u := User{
39 Name: name,
40 Type: "User",
41 Attrs: struct {
42 Email string
43 }{email},
44 }
45 buf := &bytes.Buffer{}
46 if err := json.NewEncoder(buf).Encode(u); err != nil {
47 return err
48 }
49 _, err := c.put("/objects/users/"+name, buf)
50 return err
51 }