-
Notifications
You must be signed in to change notification settings - Fork 0
/
detectonline.go
45 lines (38 loc) · 988 Bytes
/
detectonline.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
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type StreamInfo struct {
StreamKey string `json:"stream_key"`
Title string `json:"title"`
Category string `json:"category"`
IsLive bool `json:"is_live"`
}
func CheckStreamStatus(streamKey string) (StreamInfo, error) {
url := fmt.Sprintf("http://example.com/stream_info?key=%s", streamKey)
resp, err := http.Get(url)
if err != nil {
return StreamInfo{}, err
}
defer resp.Body.Close()
var info StreamInfo
if err := json.NewDecoder(resp.Body).Decode(&info); err != nil {
return StreamInfo{}, err
}
return info, nil
}
func main() {
streamKey := "your_stream_key_here"
info, err := CheckStreamStatus(streamKey)
if err != nil {
fmt.Printf("Error checking stream status: %v\n", err)
return
}
if info.IsLive {
fmt.Printf("Stream %s is live with title '%s' in category '%s'\n", info.StreamKey, info.Title, info.Category)
} else {
fmt.Printf("Stream %s is not live\n", info.StreamKey)
}
}