Blob
1 package icinga3 import (4 "bytes"5 "encoding/json"6 "fmt"7 "net/http"8 )10 type User struct {11 Name string12 Type string13 Attrs struct {14 Email string15 }16 }18 var testUser = User{19 Name: "Olly",20 Type: "User",21 Attrs: struct {22 Email string23 }{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, err30 }31 if resp.StatusCode != http.StatusOK {32 return nil, fmt.Errorf("get /objects/users: status %s", resp.Status)33 }34 return []User{testUser}, nil35 }37 func (c *Client) CreateUser(name, email string) error {38 u := User{39 Name: name,40 Type: "User",41 Attrs: struct {42 Email string43 }{email},44 }45 buf := &bytes.Buffer{}46 if err := json.NewEncoder(buf).Encode(u); err != nil {47 return err48 }49 _, err := c.put("/objects/users/"+name, buf)50 return err51 }
