package live import ( "fmt" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" aliyunlive "github.com/alibabacloud-go/live-20161101/client" runtime "github.com/alibabacloud-go/tea-utils/v2/service" ) type aliyunLiveClient struct { client *aliyunlive.Client pushDomain string appName string } func newAliyunLiveClient(cfg Config) (*aliyunLiveClient, error) { apiConfig := &openapi.Config{} apiConfig.SetAccessKeyId(cfg.AccessKeyID). SetAccessKeySecret(cfg.AccessKeySecret). SetRegionId(cfg.RegionID) if cfg.APIEndpoint != "" { apiConfig.SetEndpoint(cfg.APIEndpoint) } client, err := aliyunlive.NewClient(apiConfig) if err != nil { return nil, fmt.Errorf("create aliyun live client: %w", err) } return &aliyunLiveClient{client: client, pushDomain: cfg.PushDomain, appName: cfg.AppName}, nil } func (c *aliyunLiveClient) queryOnline(streamName string) (OnlineStatus, error) { request := (&aliyunlive.DescribeLiveStreamsOnlineListRequest{}). SetAppName(c.appName). SetDomainName(c.pushDomain). SetStreamName(streamName). SetPageNum(1). SetPageSize(100) response, err := c.client.DescribeLiveStreamsOnlineListWithOptions(request, &runtime.RuntimeOptions{}) if err != nil { return OnlineStatus{}, fmt.Errorf("describe aliyun live stream: %w", err) } if response == nil || response.Body == nil || response.Body.OnlineInfo == nil { return OnlineStatus{}, nil } for _, item := range response.Body.OnlineInfo.LiveStreamOnlineInfo { if item != nil && item.StreamName != nil && *item.StreamName == streamName { return OnlineStatus{Online: true}, nil } } return OnlineStatus{}, nil }