-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_all_channels.go
48 lines (37 loc) · 986 Bytes
/
get_all_channels.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
package channels
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/wakumaku/go-zulip"
)
type GetAllChannelsResponse struct {
zulip.APIResponseBase
getAllChannelsResponseData
}
type getAllChannelsResponseData struct {
Streams []ChannelInfo `json:"streams"`
}
func (g *GetAllChannelsResponse) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &g.APIResponseBase); err != nil {
return err
}
if err := json.Unmarshal(b, &g.getAllChannelsResponseData); err != nil {
return err
}
return nil
}
// GetAllChannels Get all channels that the user has access to.
func (svc *Service) GetAllChannels(ctx context.Context, streamID int) (*GetAllChannelsResponse, error) {
const (
method = http.MethodGet
path = "/api/v1/streams/%d/members"
)
patchPath := fmt.Sprintf(path, streamID)
resp := GetAllChannelsResponse{}
if err := svc.client.DoRequest(ctx, method, patchPath, nil, &resp); err != nil {
return nil, err
}
return &resp, nil
}