This topic describes how to initialize the client of ApsaraVideo for Media Processing (MPS) SDK for Go V2.0.
Prerequisites
MPS SDK for Go V2.0 is installed. For more information, see Install Install MPS SDK for Go.
The endpoint of MPS in a region is obtained. For example, if your MPS service is deployed in the China (Shanghai) region, the region ID is
cn-shanghai. For more information about the regions in which MPS is available, see Endpoints.
Initialize the SDK client
Construct the request client. You must obtain an AccessKey pair for authentication before you initialize the SDK client. For more information about how to obtain an AccessKey pair, see Create an AccessKey pair.
config := &openapi.Config{
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
}
config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
Sample code:
import (
mts "github.com/alibabacloud-go/mts-20140618/v6/client"
openapi "github.com/alibabacloud-go/darabonba-openapi/client"
)
// Description:
//
// Use your AccessKey ID and AccessKey secret to initialize a client.
//
// @return Client
//
// @throws Exception
func CreateClient () (_result *mts20140618.Client, _err error) {
config := &openapi.Config{
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
}
config.Endpoint = tea.String("mts.cn-hangzhou.aliyuncs.com")
_result = &mts20140618.Client{}
_result, _err = mts20140618.NewClient(config)
return _result, _err
}
func _main (args []*string) (_err error) {
client, _err := CreateClient()
if _err != nil {
return _err
}