package main import ( "encoding/json" "errors" "log" "net/http" "net/url" ) func getUsers(token string, channel string) ([]string, error) { u, _ := url.Parse("https://slack.com/api/channels.info") u.Query().Set("token", token) u.Query().Set("channel", channel) req, err := http.NewRequest(http.MethodGet, u.String(), nil) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp, err := getClient().Do(req) if err != nil { log.Println(err) return nil, err } r := struct { OK bool `json:"ok"` Error string `json:"error"` Channel struct { Members []string `json:"members"` } `json:"channel"` }{} if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { return nil, err } if !r.OK { return nil, errors.New(r.Error) } return r.Channel.Members, nil }