-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
65 lines (51 loc) · 1.21 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"log"
"gopkg.in/jmcvetta/napping.v1"
)
// UserResponse list of users
type UserResponse struct {
Ok bool
Members []Member
}
// Member single member
type Member struct {
ID string
Name string
Deleted bool
RealName string `json:"real_name"`
Profile Profile
}
// Profile user profile
type Profile struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string
Image192 string `json:"image_192"`
}
var users []Member
func loadUsers() {
var err interface{}
var userResponse UserResponse
var reqParams = &napping.Params{"token": config.SlackToken}
napping.Get("https://slack.com/api/users.list", reqParams, &userResponse, err)
log.Printf("Loaded %d users\n", len(userResponse.Members))
users = userResponse.Members
}
func findMemberByTag(tag string) (Member, error) {
for _, user := range users {
if user.Name == tag {
return user, nil
}
}
return Member{}, fmt.Errorf("Member with tag %s could not be found!", tag)
}
func findMemberByID(ID string) (Member, error) {
for _, user := range users {
if user.ID == ID {
return user, nil
}
}
return Member{}, fmt.Errorf("Member with ID %s could not be found!", ID)
}