-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitch.go
More file actions
40 lines (36 loc) · 986 Bytes
/
twitch.go
File metadata and controls
40 lines (36 loc) · 986 Bytes
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
package gtvapi
import (
"context"
"fmt"
)
// LiveCheck checks the live status of Twitch channels associated with Gronkh.TV.
//
// Parameters:
// - ctx: Context for cancellation and timeout control
//
// Returns a map of channel names to their live status information,
// or an error if the request fails.
//
// Example:
//
// ctx := context.Background()
// channels, err := client.LiveCheck(ctx)
// if err != nil {
// log.Fatal(err)
// }
// for name, info := range channels {
// if info.IsLive {
// fmt.Printf("%s is live with %d viewers\n", name, info.ViewerCount)
// }
// }
func (c *Client) LiveCheck(ctx context.Context) (map[ChannelName]*ChannelInfo, error) {
data, err := c.get(ctx, string(externalTwitchLivecheckEndpoint), nil)
if err != nil {
return nil, fmt.Errorf("failed to check live status: %w", err)
}
var response LiveCheck
if err := unmarshalResponse(data, &response); err != nil {
return nil, err
}
return response.Channels, nil
}