视频直播 LIVE-Go SDK使用指导:代码示例

时间:2024-07-02 19:12:59

代码示例

调用前请根据实际情况替换如下变量:{your endpoint} 以及 {your project id}。

认证用的AK、SK直接写入代码,会有很大安全风险,建议密文形式存放在配置文件或者环境变量中,待使用时再解密,以确保安全。

本示例以AK、SK保存在环境变量中为例。运行本示例前,请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。

 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
49
package main

import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/httphandler"
    live "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/live/v1"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/live/v1/model"
    "net/http"
    "os"
)

func RequestHandler(request http.Request) {
    fmt.Println(request)
}

func ResponseHandler(response http.Response) {
    fmt.Println(response)
}

func main() {
    client := live.NewLiveAPIClient(
        live.LiveAPIClientBuilder().
            WithEndpoints([]string{"{your endpoint}"}).
            WithCredential(
                basic.NewCredentialsBuilder().
                    WithAk(os.Getenv("HUAWEICLOUD_SDK_AK")).
                    WithSk(os.Getenv("HUAWEICLOUD_SDK_SK")).
                    WithProjectId("{your project id}").
                    Build()).
            WithHttpConfig(config.DefaultHttpConfig().
                WithIgnoreSSLVerification(true).
                WithHttpHandler(httphandler.
                    NewHttpHandler().
                        AddRequestHandler(RequestHandler).
                        AddResponseHandler(ResponseHandler))).
            Build())

    request := &model.ShowTranscodingsTemplateRequest{
        Domain: "play.example.huaweicloud.com",
    }
    response, err := client.ShowTranscodingsTemplate(request)
    if err == nil {
        fmt.Println("%+v\n",response)
    } else {
        fmt.Println(err)
    }
}
support.huaweicloud.com/ssdk-live/live_18_0004.html