This topic describes how to use the server SDK for Go provided by ApsaraVideo Live and provides sample code. It uses the API that adds a domain name as an example to show you how to call an ApsaraVideo Live API.
Environment requirement
Go 1.10.x or later.
Procedure
Log on to SDK Center. Set SDK Generation to V2.0 and select Go for the language. On the Quick Start tab, find the installation method section.

Create a project and use the Credentials tool to manage your access credentials. For more information, see Manage access credentials.
Send a request and handle the response or exceptions.
// This file is auto-generated, don't edit it. Thanks. package main import ( "encoding/json" "strings" "fmt" "os" live20161101 "github.com/alibabacloud-go/live-20161101/v2/client" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" util "github.com/alibabacloud-go/tea-utils/v2/service" credential "github.com/aliyun/credentials-go/credentials" "github.com/alibabacloud-go/tea/tea" ) // Description: // // Initialize a client using credentials. // // @return Client // // @throws Exception func CreateClient () (_result *live20161101.Client, _err error) { // Avoid hardcoding your AccessKey pair. For more information, see https://help.alibabacloud.com/document_detail/378661.html. credential, _err := credential.NewCredential(nil) if _err != nil { return _result, _err } config := &openapi.Config{ Credential: credential, } // For endpoints, see https://api.alibabacloud.com/product/live. config.Endpoint = tea.String("live.aliyuncs.com") _result = &live20161101.Client{} _result, _err = live20161101.NewClient(config) return _result, _err } func _main (args []*string) (_err error) { client, _err := CreateClient() if _err != nil { return _err } addLiveDomainRequest := &live20161101.AddLiveDomainRequest{} runtime := &util.RuntimeOptions{} tryErr := func()(_e error) { defer func() { if r := tea.Recover(recover()); r != nil { _e = r } }() // Print the return value of the API. _, _err = client.AddLiveDomainWithOptions(addLiveDomainRequest, runtime) if _err != nil { return _err } return nil }() if tryErr != nil { var error = &tea.SDKError{} if _t, ok := tryErr.(*tea.SDKError); ok { error = _t } else { error.Message = tea.String(tryErr.Error()) } // The following code is for demonstration purposes only. Handle exceptions with caution. Do not ignore exceptions in your project. // Error message fmt.Println(tea.StringValue(error.Message)) // Diagnosis address var data interface{} d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data))) d.Decode(&data) if m, ok := data.(map[string]interface{}); ok { recommend, _ := m["Recommend"] fmt.Println(recommend) } _, _err = util.AssertAsString(error.Message) if _err != nil { return _err } } return _err } func main() { err := _main(tea.StringSlice(os.Args[1:])) if err != nil { panic(err) } }
For API reference, see List of operations by function.