视频直播 Live-Go SDK使用指导:代码示例
代码示例
调用前请根据实际情况替换如下变量:{your endpoint} 以及 {your project id}。
认证用的AK、SK直接写入代码,会有很大安全风险,建议密文形式存放在配置文件或者环境变量中,待使用时再解密,以确保安全。
本示例以AK、SK保存在环境变量中为例。运行本示例前,请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
package mainimport ( "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) }} |