Initialize a client
Updated at:
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 MPS SDK for Go.
-
You have the endpoint of MPS for your region. For example, if MPS is deployed in the China (Shanghai) region, the region ID is
cn-shanghai. For more information, see Endpoints.
Initialize the SDK client
To initialize the SDK client, construct a request client with an AccessKey pair for authentication. For more information, 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
}
Is this page helpful?