forked from marpaia/chef-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
36 lines (32 loc) · 780 Bytes
/
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
package chef
import (
"encoding/json"
)
// chef.GetUsers returns a map of user names to the users RESTful URL as well
// as an error indicating if the request was successful or not.
//
// Usage:
//
// users, err := chef.GetUsers()
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }
// // do what you please with the "user" variable which is a map of
// // user names to user URLs
// for user := range users {
// fmt.Println(user)
// }
func (chef *Chef) GetUsers() (map[string]string, error) {
resp, err := chef.Get("users")
if err != nil {
return nil, err
}
body, err := responseBody(resp)
if err != nil {
return nil, err
}
users := map[string]string{}
json.Unmarshal(body, &users)
return users, nil
}