Categorygithub.com/aliyun/fc-go-sdk
modulepackage
0.0.0-20230313060359-3a1b2ede1e1e
Repository: https://github.com/aliyun/fc-go-sdk.git
Documentation: pkg.go.dev

# README

Aliyun FunctionCompute Go SDK

API Reference :

FC API

GitHub Version Build Status

VERSION

go >= 1.8

Overview

Aliyun FunctionCompute Go SDK, sample

package main

import (
	"fmt"
	"os"
	"github.com/aliyun/fc-go-sdk"
)

func main() {
	serviceName := "service555"
	client, _ := fc.NewClient(os.Getenv("ENDPOINT"), "2016-08-15", os.Getenv("ACCESS_KEY_ID"), os.Getenv("ACCESS_KEY_SECRET"))

	fmt.Println("Creating service")
	createServiceOutput, err := client.CreateService(fc.NewCreateServiceInput().
		WithServiceName(serviceName).
		WithDescription("this is a smoke test for go sdk"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	}
	if createServiceOutput != nil {
		fmt.Printf("CreateService response: %s \n", createServiceOutput)
	}

	// GetService
	fmt.Println("Getting service")
	getServiceOutput, err := client.GetService(fc.NewGetServiceInput(serviceName))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("GetService response: %s \n", getServiceOutput)
	}

	// UpdateService
	fmt.Println("Updating service")
	updateServiceInput := fc.NewUpdateServiceInput(serviceName).WithDescription("new description")
	updateServiceOutput, err := client.UpdateService(updateServiceInput)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("UpdateService response: %s \n", updateServiceOutput)
	}

	// UpdateService with IfMatch
	fmt.Println("Updating service with IfMatch")
	updateServiceInput2 := fc.NewUpdateServiceInput(serviceName).WithDescription("new description2").
		WithIfMatch(updateServiceOutput.Header.Get("ETag"))
	updateServiceOutput2, err := client.UpdateService(updateServiceInput2)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("UpdateService response: %s \n", updateServiceOutput2)
	}

	// UpdateService with wrong IfMatch
	fmt.Println("Updating service with wrong IfMatch")
	updateServiceInput3 := fc.NewUpdateServiceInput(serviceName).WithDescription("new description2").
		WithIfMatch("1234")
	updateServiceOutput3, err := client.UpdateService(updateServiceInput3)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("UpdateService response: %s \n", updateServiceOutput3)
	}

	// ListServices
	fmt.Println("Listing services")
	listServicesOutput, err := client.ListServices(fc.NewListServicesInput().WithLimit(100))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("ListServices response: %s \n", listServicesOutput)
	}

	// CreateFunction
	fmt.Println("Creating function1")
	createFunctionInput1 := fc.NewCreateFunctionInput(serviceName).WithFunctionName("testf1").
        		WithDescription("go sdk test function").
        		WithHandler("main.my_handler").WithRuntime("python2.7").
        		WithCode(fc.NewCode().WithFiles("./testCode/hello_world.zip")).
        		WithTimeout(5)

	createFunctionOutput, err := client.CreateFunction(createFunctionInput1)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("CreateFunction response: %s \n", createFunctionOutput)
	}
	fmt.Println("Creating function2")
	createFunctionOutput2, err := client.CreateFunction(createFunctionInput1.WithFunctionName("testf2"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("CreateFunction response: %s \n", createFunctionOutput2)
	}

	// ListFunctions
	fmt.Println("Listing functions")
	listFunctionsOutput, err := client.ListFunctions(fc.NewListFunctionsInput(serviceName).WithPrefix("test"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("ListFunctions response: %s \n", listFunctionsOutput)
	}

	// UpdateFunction
	fmt.Println("Updating function")
	updateFunctionOutput, err := client.UpdateFunction(fc.NewUpdateFunctionInput(serviceName, "testf1").
		WithDescription("newdesc"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("UpdateFunction response: %s \n", updateFunctionOutput)
	}

	// InvokeFunction
	fmt.Println("Invoking function, log type Tail")
	invokeInput := fc.NewInvokeFunctionInput(serviceName, "testf1").WithLogType("Tail")
	invokeOutput, err := client.InvokeFunction(invokeInput)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("InvokeFunction response: %s \n", invokeOutput)
		logResult, err := invokeOutput.GetLogResult()
		if err != nil {
			fmt.Printf("Failed to get LogResult due to %v\n", err)
		} else {
			fmt.Printf("Invoke function LogResult %s \n", logResult)
		}
	}

	fmt.Println("Invoking function, log type None")
	invokeInput = fc.NewInvokeFunctionInput(serviceName, "testf1").WithLogType("None")
	invokeOutput, err = client.InvokeFunction(invokeInput)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("InvokeFunction response: %s \n", invokeOutput)
	}

    // PublishServiceVersion
	fmt.Println("Publishing service version")
	publishServiceVersionInput := fc.NewPublishServiceVersionInput(serviceName)
	publishServiceVersionOutput, err := client.PublishServiceVersion(publishServiceVersionInput)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("PublishServiceVersion response: %s \n", publishServiceVersionOutput)
	}

    // PublishServiceVersion with IfMatch
    fmt.Println("Publishing service version with IfMatch")
    publishServiceVersionInput2 := fc.NewPublishServiceVersionInput(serviceName).
	       WithIfMatch(getServiceOutput.Header.Get("ETag"))
	publishServiceVersionOutput2, err := client.PublishServiceVersion(publishServiceVersionInput2)
	if err != nil {
	     fmt.Fprintln(os.Stderr, err)
	} else {
	      fmt.Printf("PublishServiceVersion response: %s \n", publishServiceVersionOutput2)
	}

	// PublishServiceVersion with wrong IfMatch
	fmt.Println("Publishing service with wrong IfMatch")
	publishServiceVersionInput3 := fc.NewPublishServiceVersionInput(serviceName).
	       WithIfMatch("1234")
	publishServiceVersionOutput3, err := client.PublishServiceVersion(publishServiceVersionInput3)
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("PublishServiceVersion response: %s \n", publishServiceVersionOutput3)
	}

	// ListServiceVersions
	fmt.Println("Listing service versions")
	listServiceVersionsOutput, err := client.ListServiceVersions(fc.NewListServiceVersionsInput(serviceName).WithLimit(10))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("ListServiceVersions response: %s \n", listServiceVersionsOutput)
	}

	// GetService with qualifier
	fmt.Println("Getting service with qualifier")
	getServiceOutput2, err := client.GetService(fc.NewGetServiceInput(serviceName).WithQualifier(publishServiceVersionOutput.VersionID))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("GetService with qualifier response: %s \n", getServiceOutput2)
	}

	// CreateAlias
	aliasName := "alias"
	fmt.Println("Creating alias")
	createAliasOutput, err := client.CreateAlias(fc.NewCreateAliasInput(serviceName).WithAliasName(aliasName).WithVersionID(publishServiceVersionOutput.VersionID))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("CreateAlias response: %s \n", createAliasOutput)
	}

	// GetAlias
	fmt.Println("Getting alias")
	getAliasOutput, err := client.GetAlias(fc.NewGetAliasInput(serviceName, aliasName))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("GetAlias response: %s \n", getAliasOutput)
	}

	// UpdateAlias
	fmt.Println("Updating alias")
	updateAliasOutput, err := client.UpdateAlias(fc.NewUpdateAliasInput(serviceName, aliasName).WithVersionID(publishServiceVersionOutput2.VersionID))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("UpdateAlias response: %s \n", updateAliasOutput)
	}

	// ListAliases
	fmt.Println("Listing aliases")
	listAliasesOutput, err := client.ListAliases(fc.NewListAliasesInput(serviceName))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("ListAliases response: %s \n", listAliasesOutput)
	}

	// DeleteAlias
	fmt.Println("Deleting aliases")
	deleteAliasOutput, err := client.DeleteAlias(fc.NewDeleteAliasInput(serviceName, aliasName))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("DeleteAlias response: %s \n", deleteAliasOutput)
	}

	// DeleteServiceVersion
	fmt.Println("Deleting service version")
	deleteServiceVersionOutput, err := client.DeleteServiceVersion(fc.NewDeleteServiceVersionInput(serviceName, publishServiceVersionOutput.VersionID))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("DeleteServiceVersion response: %s \n", deleteServiceVersionOutput)
	}

	deleteServiceVersionOutput2, err := client.DeleteServiceVersion(fc.NewDeleteServiceVersionInput(serviceName, publishServiceVersionOutput2.VersionID))
	if err != nil {
	       fmt.Fprintln(os.Stderr, err)
	} else {
	       fmt.Printf("DeleteServiceVersion response: %s \n", deleteServiceVersionOutput2)
	}

	// DeleteFunction
	fmt.Println("Deleting functions")
	listFunctionsOutput, err = client.ListFunctions(fc.NewListFunctionsInput(serviceName).WithLimit(10))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("ListFunctions response: %s \n", listFunctionsOutput)
		for _, fuc := range listFunctionsOutput.Functions {
			fmt.Printf("Deleting function %s \n", *fuc.FunctionName)
			if output, err := client.DeleteFunction(fc.NewDeleteFunctionInput(serviceName, *fuc.FunctionName)); err != nil {
				fmt.Fprintln(os.Stderr, err)
			} else {
				fmt.Printf("DeleteFunction response: %s \n", output)
			}

		}
	}

	// DeleteService
	fmt.Println("Deleting service")
	deleteServiceOutput, err := client.DeleteService(fc.NewDeleteServiceInput(serviceName))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else {
		fmt.Printf("DeleteService response: %s \n", deleteServiceOutput)
	}

	// PutProvisionConfig
    fmt.Println("Putting provision config")
    putProvisionConfigOutput, err := client.PutProvisionConfig(fc.NewPutProvisionConfigInput(serviceName, "testAliasName", "testFunctionName").WithTarget(int64(100))
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
    } else {
        fmt.Printf("PutProvisionConfig response: %s \n", putProvisionConfigOutput)
    }

    // GetProvisionConfig
    fmt.Println("Getting provision config")
    getProvisionConfigOutput, err := client.GetProvisionConfig(fc.NewGetProvisionConfigInput(serviceName, "testAliasName", "testFunctionName"))
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
    } else {
        fmt.Printf("GetProvisionConfig response: %s \n", getProvisionConfigOutput)
    }

    // ListProvisionConfigs
    fmt.Println("Listing provision configs")
    listProvisionConfigsOutput, err := client.ListProvisionConfigs(fc.NewListProvisionConfigsInput())
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
    } else {
        fmt.Printf("ListProvisionConfigs response: %s \n", listProvisionConfigsOutput)
    }
}

More resources

Contacting us

License

# Packages

No description provided by the author

# Functions

GetAccessPoint get correct endpoint and host.
GetAuthStr get signature strings.
GetErrorType get error type when call invocation.
GetEtag get resource etag.
GetRequestID from headers.
GetSignature calculate user's signature.
GetSignResourceWithQueries get signature resource with queries.
HasPrefix check endpoint prefix.
IsBlank :check string pointer is nil or empty.
MD5 :Encoding MD5.
NewCDNEventsTriggerConfig creates an empty CDNTEventsTriggerConfig.
NewClient new fc client.
No description provided by the author
NewConfig get default config.
NewConnection get default connection.
No description provided by the author
NewCreateCustomDomainInput...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewEventBridgeTriggerConfig ...
NewEventSourceConfig ...
NewEventSourceParameters ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewGetFunctionCodeInput ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewGetResourceTagsInput...
No description provided by the author
No description provided by the author
No description provided by the author
NewHTTPTriggerConfig ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewListReservedCapacitiesInput : ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewMnsTopicTriggerConfig ..
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewSignURLInput : create sign url request.
No description provided by the author
NewSourceMNSParameters ...
SourceRabbitMQParameters ...
NewSourceRocketMQParameters ...
No description provided by the author
NewTableStoreTriggerConfig ..
NewTagResourceInput ...
NewTimeTriggerConfig creates an empty TimeTriggerConfig.
No description provided by the author
NewUnTagResourceInput ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ParameterToString serialize parameters.
TempZipDir zips everything from source dir into a temporary zip file which doesn't include the source dir but its content.
TmpZip everything from source file into a temporary zip file.
WithAccountID sets the account id in header, this enables accessing FC using IP address: client, _ := fc.NewClient("127.0.0.1", "api-version", "id", "key", fc.WithAccountID("1234776887")).
WithRetryCount : config the retry count for resty.
WithSecurityToken : sets the STS security token.
WithTimeout : set request timeout in second.
WithTransport : overrides default http.Transport with customized transport.
Zip everything from the source (either file/directory) recursively into target zip file.
ZipDir zip up a directory and preserve symlinks and empty directories.

# Constants

No description provided by the author
Supported api versions.
AuthAnonymous defines http trigger without authorized.
AuthFunction defines http trigger authorized by AK.
AuthQueryKeyAccessKeyID : keys in request queries.
AuthQueryKeyExpires : keys in request queries.
AuthQueryKeySecurityToken : keys in requres queries.
AuthQueryKeySignature : keys in request queries.
CustomContainerConfigAccelerationTypeDefault : default acceleration type for custom-container runtime.
CustomContainerConfigAccelerationTypeNone : disable custom-container runtime acceleration.
No description provided by the author
HTTPHeaderAccountID stores the account ID.
HTTPHeaderContentMD5 :Key in request headers.
HTTPHeaderContentType :Key in request headers.
HTTPHeaderDate :Key in request headers.
HTTPHeaderEtag get the etag of the resource.
HTTPHeaderFCErrorType get the error type when invoke function.
HTTPHeaderInvocationLogResult is the header key for invoke function log result.
HTTPHeaderInvocationLogType is the header key for invoke function log type.
HTTPHeaderInvocationType stores the invocation type.
HTTPHeaderPrefix :Prefix string in headers.
HTTPHeaderRequestID get request ID.
HTTPHeaderSecurityToken is the header key for STS security token.
HTTPHeaderStatefulAsyncInvocationID get invocation ID.
HTTPHeaderUserAgent : Key in request headers.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
default parameter.
Supported tracing types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

DefaultAuthType ...
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
AsyncConfig represents the async configuration.
AsyncConfigResponse defines the detail async config object.
CDNEventsTriggerConfig defines the cdn events trigger config.
No description provided by the author
Client defines fc client.
Code defines the code location or includes the base64 encoded source.
Config defines fc config.
Connection with fc.
No description provided by the author
No description provided by the author
CreateCustomDomainInput defines input to create custom domain.
CreateCustomDomainOutput define create custom domain response.
CreateFunctionInput defines function creation input.
No description provided by the author
CreateServiceInput defines input to create service.
CreateServiceOutput define get service response.
CreateTriggerInput defines trigger creation input.
No description provided by the author
Credentials defines the returned credential.
CustomContainerConfig defines the code docker image.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DeleteFunctionAsyncInvokeConfigInput defines function creation input.
DeleteFunctionAsyncInvokeConfigOutput define delete data response.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Destination represents the destination arn.
DestinationConfig represents the destination configuration.
TriggerConfig defines the event bridge trigger config which maps to FunctionComputeConfiguration.
EventSourceConfig ...
EventSourceParameters ...
No description provided by the author
FunctionUpdateObject defines update fields in Function.
GetAccountSettingsInput defines get account settings intput.
GetAccountSettingsOutput defines get account settings output.
No description provided by the author
No description provided by the author
No description provided by the author
GetCustomDomainOutput define get custom domain response.
GetFunctionAsyncInvokeConfigInput defines function creation input.
GetFunctionAsyncInvokeConfigOutput define get data response.
GetFunctionCodeInput ...
GetFunctionCodeOutput define function response from fc.
No description provided by the author
GetFunctionOutput define function response from fc.
No description provided by the author
No description provided by the author
GetLayerVersionOutput define get layer version response.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetResourceTagsInput ...
GetResourceTagsOut ...
No description provided by the author
GetServiceOutput define get service response.
GetFunctionAsyncInvokeConfigInput defines function creation input.
GetFunctionAsyncInvokeConfigOutput define get data response.
GetTempBucketTokenInput is empty.
GetTempBucketTokenOutput ...
No description provided by the author
GetTriggerOutput define trigger response from fc.
HTTPTriggerConfig ..
No description provided by the author
InstanceExecInput define publish layer version response.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
JobConfig maps to Log service's trigger config.
LogConfig ..
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ListCustomDomains defines listCustomDomainsMetadata result.
No description provided by the author
ListFunctionAsyncInvokeConfigsOutput defines ListFunctionAsyncInvokeConfigsOutput result.
No description provided by the author
ListFunctionsOutput defines the function response list.
ListInstancesInput define publish layer version response.
No description provided by the author
No description provided by the author
ListLayersOutput defines List layers result.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ListReservedCapacitiesInput : ...
ListReservedCapacitiesOutput : ...
No description provided by the author
ListServicesOutput defines listServiceMetadata result.
No description provided by the author
No description provided by the author
No description provided by the author
ListFunctionAsyncInvokeConfigsOutput defines ListFunctionAsyncInvocationsOutput result.
No description provided by the author
ListTriggersOutput defines the trigger response list.
LogConfig defines the log config for service.
LogTriggerConfig ..
MnsTopicTriggerConfig ..
NASConfig defines the NAS config info UserID/GroupID is the uid/gid of the user access the NFS file system.
NASMountConfig defines the nas binding info for service.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OutputCodeLocation represents the output code location.
PathConfig represents path-function mapping.
No description provided by the author
PublishLayerVersionInput defines input to create layer version.
PublishLayerVersionOutput define publish layer version response.
No description provided by the author
No description provided by the author
No description provided by the author
PutFunctionAsyncInvokeConfigInput defines function creation input.
PutFunctionAsyncInvokeConfigOutput define get async config response.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RouteConfig represents route config for a single domain.
ServiceError defines error from fc.
ServiceUpdateObject defines the service update fields.
No description provided by the author
SignURLInput ...
SourceConfig ..
SourceMNSParameters refers to github.com/alibabacloud-go/eventbridge-sdk v1.2.10.
SourceRocketMQParameters refers to ithub.com/alibabacloud-go/eventbridge-sdk v1.2.10.
SourceRocketMQParameters refers to github.com/alibabacloud-go/eventbridge-sdk v1.2.10.
StatefulAsyncInvocation represents the stateful async invocation records.
No description provided by the author
StopStatefulAsyncInvocationInput defines function creation input.
StopStatefulAsyncInvocationOutput ...
TableStoreTriggerConfig ..
TagResourceInput defines input to tag a resource(service).
TagResourceOut ...
TimeTriggerConfig defines the time trigger config.
No description provided by the author
No description provided by the author
TriggerUpdateObject defines update fields in Trigger.
UnTagResourceInput ...
UnTagResourceOut ...
No description provided by the author
No description provided by the author
No description provided by the author
UpdateCustomDomainInput defines input to update custom domain.
UpdateCustomDomainOutput define update custom domain response.
No description provided by the author
No description provided by the author
No description provided by the author
UpdateServiceOutput define get service response.
No description provided by the author
No description provided by the author
VPCConfig defines the VPC config for service.

# Interfaces

No description provided by the author

# Type aliases

ClientOption : defines client options type.
No description provided by the author
No description provided by the author
OSSEvent represents the oss event type in oss trigger.