Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Go SDK

Updated on 2024-05-09 GMT+08:00

This section describes how to quickly integrate Go SDKs for development.

Prerequisites

  • You have registered with Huawei Cloud and completed real-name authentication.
    NOTE:

    If you are a Huawei Cloud (International) user, you need to complete real-name authentication when you:

    • Purchase and use cloud services on Huawei Cloud nodes in the Chinese mainland. In this case, real-name authentication is required by the laws and regulations of the Chinese mainland.
    • Select the Chinese mainland region for MPC.
  • The development environment (Go 1.14 or later) is available.
  • You have obtained the access key (AK) and secret access key (SK) of the account. You can create and view your AK/SK on the My Credentials > Access Keys page of the console. For details, see Access Keys.
  • You have obtained the project ID of the corresponding region of MPC. You can view the project ID on the My Credentials > API Credentials page of the console. For details, see API Credentials.
  • You have uploaded the media asset files to an OBS bucket in the region of MPC, and authorized MPC to access the OBS bucket. For details, see Uploading Media Files and Authorizing Access to Cloud Resources.

Installing SDK

The Go SDK for media transcoding supports Go 1.14 or later. Run the go version command to check the Go version.

Run the go get command to install the Go SDK. Then run the following commands to install the Go SDK library and dependencies. For details about the SDK version, see SDK Center.

1
2
3
4
# Install the Go library.
go get github.com/huaweicloud/huaweicloud-sdk-go-v3
 # Install dependent libraries.
go get github.com/json-iterator/go

Procedure

  1. Import the dependent module.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    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"
        "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mpc/v1"
        "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mpc/v1/model"
        "net/http"
    )
    

  2. Configure client attributes.

    1. Use the default configuration.
      1
      2
      # Use default configuration
      httpConfig := config.DefaultHttpConfig()
      
    2. (Optional) Configure the proxy.
      1
      2
      3
      4
      5
      6
      7
      8
      9
      username := os.Getenv("USER_NAME")
      password := os.Getenv("USER_PASSWARD")
      // Configure the network proxy as required.
      httpConfig.WithProxy(config.NewProxy().
          WithSchema("http").
          WithHost("proxy.huaweicloud.com").
          WithPort(80).
          WithUsername(username).
          WithPassword(password))
      
    3. (Optional) Configure SSL.
      1
      2
      // Configure whether to skip SSL certificate verification as required.
      httpConfig.WithIgnoreSSLVerification(true);
      

  3. Initialize authentication information.

    You can use one of the following two authentication modes:

    • Permanent AK/SK

      Obtain the permanent AK, SK, and project ID. For details, see Prerequisites.

      1
      2
      3
      4
      5
      6
      7
      8
      ak := os.Getenv("SDK_AK")
      sk := os.Getenv("SDK_SK")
      projectId := os.Getenv("PROJECT_ID")
      auth := basic.NewCredentialsBuilder().
                  WithAk(ak).
                  WithSk(sk).
                  WithProjectId(projectId).
                  Build()
      
    • Temporary AK/SK

      Obtain a temporary AK, SK, and security token. For details, see Obtaining a Temporary Access Key and Security Token Through a Token or Obtaining a Temporary Access Key and Security Token Through an Agency.

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      ak := os.Getenv("SDK_AK")
      sk := os.Getenv("SDK_SK")
      projectId := os.Getenv("PROJECT_ID")
      securityToken := os.Getenv("SECURITY_TOKEN")
      auth := basic.NewCredentialsBuilder().
                  WithAk(ak).
                  WithSk(sk).
                  WithProjectId(projectId).
                  WithSecurityToken(securityToken).
                  Build()
      
    The related parameters are as follows:
    • ak: access key of an account
    • sk: secret access key of an account
    • projectId: ID of the project where MPC is provided. Select a project ID based on the region of the project.
    • securityToken: security token used for temporary AK/SK authentication

  4. Initialize the client.

    1
    2
    3
    4
    5
    6
    7
    8
    # Initialize the MPC client.
    client := mpc.NewMpcClient
    (
        mpcMpcClientBuilder().
            WithEndpoint(endpoint).     // endpoint value, for example, "https://mpc.region01.myhuaweicloud.com"
            WithCredential(auth).
            WithHttpConfig(config.DefaultHttpConfig()).  
            Build())
    

    endpoint: regions where MPC is used and endpoints of each service. For details, see Regions and Endpoints.

  5. Send a request and view the response.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    // Initialize the request. The following uses the API for querying transcoding templates as an example.
    request := &model.ListTranscodingTaskRequest{    
        TaskId:&[]int64{1900293},
    }
    response, err := client.ListTranscodingTask(request)
    if err == nil {
        fmt.Printf("%+v\n",response)
    } else {
        fmt.Println(err)
    }
    

  6. Perform troubleshooting.

    Table 1 Troubleshooting

    Level 1

    Description

    ServiceResponseError

    Service response error

    url.Error

    Endpoint connection error

    1
    2
    3
    4
    5
    6
    7
    # Troubleshooting
    response, err := client.ListTranscodingTask(request)
    if err == nil {
        fmt.Println(response)
    } else {
        fmt.Println(err)
    }
    

  7. Use the listener to obtain original HTTP requests and responses.

    The original HTTP requests and responses are required for debugging HTTP requests sent by the service side. The SDK provides the listener to obtain the original and encrypted HTTP requests and responses.

    CAUTION:

    Original information is printed only during debugging. Do not print the header and body of an original HTTP request in the production system because this information contains sensitive data but is not encrypted. If the request body is binary, that is, Content-Type is set to binary, the body will be displayed as *** without the detailed content.

     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
    func RequestHandler(request http.Request) {
        fmt.Println(request)
    }
    
    func ResponseHandler(response http.Response) {
        fmt.Println(response)
    }
    
    ak := os.Getenv("SDK_AK")
    sk := os.Getenv("SDK_SK")
    projectId := os.Getenv("{your project id}")
    client := mpc.NewMpcClient(
        mpc.MpcClientBuilder().
            WithEndpoint("{your endpoint}").
            WithCredential(
                basic.NewCredentialsBuilder().
                    WithAk(ak).
                    WithSk(sk).
                    WithProjectId(projectId).
                       Build()).
            WithHttpConfig(config.DefaultHttpConfig().
                WithIgnoreSSLVerification(true).
                WithHttpHandler(httphandler.
                    NewHttpHandler().
                        AddRequestHandler(RequestHandler).
                        AddResponseHandler(ResponseHandler))).Build())
    

Sample Code

Before calling this API, replace SDK_AK, SDK_SK, {your endpoint string}, and {your project id} with the actual ones.
 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
50
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"
    mpc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mpc/v1"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mpc/v1/model"
    "net/http"
)

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

func ResponseHandler(response http.Response) {
    fmt.Println(response)
}
ak := os.Getenv("SDK_AK")
sk := os.Getenv("SDK_SK")
projectId := os.Getenv("{your project id}")
func main() {
    client := mpc.NewMpcClient(
        mpc.MpcClientBuilder().
            WithEndpoint("{your endpoint}").
            WithCredential(
                basic.NewCredentialsBuilder().
                    WithAk(ak).
                    WithSk(sk).
                    WithProjectId(projectId).
                    Build()).
            WithHttpConfig(config.DefaultHttpConfig().
                WithIgnoreSSLVerification(true).
                WithHttpHandler(httphandler.
                    NewHttpHandler().
                        AddRequestHandler(RequestHandler).
                        AddResponseHandler(ResponseHandler))).
            Build())

    request := &model.ListTranscodingTaskRequest{        
        TaskId:&[]int64{1900293},
    }
    response, err := client.ListTranscodingTask(request)
    if err == nil {
        fmt.Println("%+v\n",response)
    } else {
        fmt.Println(err)
    }
}

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback