Package list golang-github-nlopes-slack / 13eb5ea
Add some examples. Clarify certain things in the README. Norberto Lopes 6 years ago
3 changed file(s) with 88 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 Slack API in Go
1
2 ## Installing
3
4 ### *go get*
5
6 $ go get github.com/nlopes/slack
7
8 ## Example
9
10 ### Getting all groups
11
12 import (
13 "fmt"
14
15 "github.com/nlopes/slack"
16 )
17
18 func main() {
19 api := slack.New("YOUR_TOKEN_HERE")
20 // If you set debugging, it will log all requests to the console
21 // Useful when encountering issues
22 // api.SetDebug(true)
23 groups, err := api.GetGroups(false)
24 if err != nil {
25 fmt.Printf("%s\n", err)
26 return
27 }
28 for _, group := range groups {
29 fmt.Printf("Id: %s, Name: %s\n", group.Id, group.Name)
30 }
31 }
32
33 ### Getting User Information
34
35 import (
36 "fmt"
37
38 "github.com/nlopes/slack"
39 )
40
41 func main() {
42 api := slack.New("YOUR_TOKEN_HERE")
43 user, err := api.GetUserInfo("U023BECGF")
44 if err != nil {
45 fmt.Printf("%s\n", err)
46 return
47 }
48 fmt.Printf("Id: %s, Fullname: %s, Email: %s\n", user.Id, user.Profile.RealName, user.Profile.Email)
49 }
150
251 ## Why?
352 I am currently learning Go and this seemed like a good idea.
0 package main
1
2 import (
3 "fmt"
4
5 "github.com/nlopes/slack"
6 )
7
8 func main() {
9 api := slack.New("YOUR_TOKEN_HERE")
10 // If you set debugging, it will log all requests to the console
11 // Useful when encountering issues
12 // api.SetDebug(true)
13 groups, err := api.GetGroups(false)
14 if err != nil {
15 fmt.Printf("%s\n", err)
16 return
17 }
18 for _, group := range groups {
19 fmt.Printf("Id: %s, Name: %s\n", group.Id, group.Name)
20 }
21 }
0 package main
1
2 import (
3 "fmt"
4
5 "github.com/nlopes/slack"
6 )
7
8 func main() {
9 api := slack.New("YOUR_TOKEN_HERE")
10 user, err := api.GetUserInfo("U023BECGF")
11 if err != nil {
12 fmt.Printf("%s\n", err)
13 return
14 }
15 fmt.Printf("Id: %s, Fullname: %s, Email: %s\n", user.Id, user.Profile.RealName, user.Profile.Email)
16 }