This repository has been archived by the owner on Jun 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGetFollowers.go
60 lines (53 loc) · 1.48 KB
/
GetFollowers.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
package hitGox
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"strings"
just "github.com/toby3d/hitGox/tools"
f "github.com/valyala/fasthttp"
)
// Team is about group information.
type Followers struct {
Request struct {
This string `json:"this"`
} `json:"request"`
Followers []struct {
Followers string `json:"followers"`
UserName string `json:"user_name"`
UserID string `json:"user_id"`
UserLogo string `json:"user_logo"`
UserLogoSmall string `json:"user_logo_small"`
FollowID string `json:"follow_id"`
FollowerUserID string `json:"follower_user_id"`
FollowerNotify string `json:"follower_notify"`
DateAdded string `json:"date_added"`
} `json:"followers"`
MaxResults string `json:"max_results"`
}
// GetFollowers returns a list of users following channel.
func GetFollowers(channel string, offset, limit int, reverse bool, sort []string) (*Followers, error) {
var args f.Args
switch {
case offset > 0:
args.Add("offset", strconv.Itoa(offset))
fallthrough
case limit > 0:
args.Add("limit", strconv.Itoa(limit))
fallthrough
case reverse:
args.Add("reverse", strconv.FormatBool(reverse))
fallthrough
case sort != nil:
args.Add("sort", fmt.Sprintf("%s", strings.Join(sort, ",")))
}
url := fmt.Sprintf(APIEndpoint, fmt.Sprint("followers/user/", channel))
resp, err := just.GET(url, &args)
if err != nil {
return nil, err
}
var obj Followers
json.NewDecoder(bytes.NewReader(resp)).Decode(&obj)
return &obj, nil
}