-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_channel_by_id.go
48 lines (37 loc) · 971 Bytes
/
get_channel_by_id.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 GetChannelByIDResponse struct {
zulip.APIResponseBase
getChannelByIDResponseData
}
type getChannelByIDResponseData struct {
Stream ChannelInfo `json:"stream"`
}
func (g *GetChannelByIDResponse) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &g.APIResponseBase); err != nil {
return err
}
if err := json.Unmarshal(b, &g.getChannelByIDResponseData); err != nil {
return err
}
return nil
}
// GetChannelByID Fetch details for the channel with the ID.
func (svc *Service) GetChannelByID(ctx context.Context, streamID int) (*GetChannelByIDResponse, error) {
const (
method = http.MethodGet
path = "/api/v1/streams/%d"
)
patchPath := fmt.Sprintf(path, streamID)
resp := GetChannelByIDResponse{}
if err := svc.client.DoRequest(ctx, method, patchPath, nil, &resp); err != nil {
return nil, err
}
return &resp, nil
}