Diese Seite ist in Ihrer lokalen Sprache noch nicht verfügbar. Wir arbeiten daran, weitere Sprachversionen hinzuzufügen. Vielen Dank für Ihre Unterstützung.

On this page

Show all

Go SDK

Updated on 2024-12-06 GMT+08:00

A synchronous function execution SDK is used as an example. To use the sample code, you must add the SDK dependency with the same language.

Table 1 Go SDK information

SDK Info

Description

Installation

go get -u github.com/huaweicloud/huaweicloud-sdk-go-v3

Links

SDK Dependency

Go SDK User Guide

The request/response parameters and example requests/responses of the SDK are the same as those of the corresponding APIs. For details about the parameters and examples, see the API for executing a function synchronously.

SDK Request Example

package main
 
import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    functiongraph "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/region"
)

func main() {
    // This example is only used for testing purposes. Do not hardcode your AK/SK in the production environment.
    ak := "<YOUR AK>"
    sk := "<YOUR SK>"
    securityToken := os.Getenv("HUAWEICLOUD_SDK_SECURITY_TOKEN")
    projectId := "{your projectId string}"
 
    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithSecurityToken(securityToken).
        WithProjectId(projectId).
        SafeBuild()
 
    client := functiongraph.NewFunctionGraphClient(
        functiongraph.FunctionGraphClientBuilder().
            WithRegion(region.ValueOf("<region>")).
            WithCredential(auth).
            Build())
 
request := &model.InvokeFunctionRequest{}
xCffLogTypeRequest:= "tail"
request.XCffLogType = &xCffLogTypeRequest
xCFFRequestVersionRequest:= "v1"
request.XCFFRequestVersion = &xCFFRequestVersionRequest
request.FunctionUrn = "urn:fss:<region>:<project_id>:function:default:<func_name>:<version>"
    response, err := client.InvokeFunction(request)
    if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}
NOTE:

Obtain AK/SK, region (endpoint), and project_id by referring to AK/SK Signing and Authentication Guide.

Obtain func_name and version from the function details page.

xCFFRequestVersionRequest indicates the response body format. v0: text format; v1: JSON format. Select this format when using an SDK.

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback