This topic provides answers to some frequently asked questions about the integration of Alibaba Cloud SDK for Go. This helps you efficiently use Alibaba Cloud SDK for Go for development.
Prerequisites
Go 1.10.x or later is installed.
Make sure that Alibaba Cloud APIs are reachable over your network.
Overview
Problems and solutions
How do I handle AccessKey errors?
Problem: The following error message is returned after running code. The error message indicates that the AccessKey pair is not correctly configured.
Alibaba Cloud SDK V2.0: InvalidCredentials: Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly.
Alibaba Cloud SDK V1.0: SDK.ServerError InvalidAccessKeyId.NotFound Specified access key is not found.
Solutions:
Run the following commands to check whether the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured.
Linux/macOS
echo $ALIBABA_CLOUD_ACCESS_KEY_ID echo $ALIBABA_CLOUD_ACCESS_KEY_SECRETWindows
echo %ALIBABA_CLOUD_ACCESS_KEY_ID% echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%If a valid AccessKey pair is returned, the environment variables are properly configured. If no AccessKey pair or an invalid AccessKey pair is returned, configure the environment variables as required. For more information, see Configure environment variables in Linux, macOS, and Windows.
Check for errors related to the AccessKey pair in the code.
Sample error request:
config := &openapi.Config{ AccessKeyId: tea.String(os.Getenv("yourAccessKeyID")), AccessKeySecret: tea.String(os.Getenv("yourAccessKeySecret")), }Sample success request:
config := &openapi.Config{ AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")), AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")), }Noteos.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID") and os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") specify that the AccessKey ID and AccessKey secret are obtained from the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
ImportantTo prevent security risks, do not write the AccessKey pair in the online code.
Which error codes are returned if Alibaba Cloud SDKs cannot connect to Alibaba Cloud services?
One of the following error codes can be returned:
InvalidAccessKeyId: Check whether your AccessKey ID is valid.
SignatureDoesNotMatch: Check whether your AccessKey secret is valid.
Check your network connection and make sure that requests are not blocked by firewalls.
What do I do if the API request times out and the "*net.DNSError" or "net.OpError" error is reported?
Multiple factors can cause the API request timeout. The following content describes the common causes and the corresponding solutions:
Network connection issues
Cause: The request cannot reach the server because the network connection between the client and server fails or the network is unstable.
Solutions:
Run the ping or curl command to test the connectivity between the on-premises host and the endpoint of the cloud service. For example, run the ping dysmsapi.aliyuncs.com or curl -v https://dysmsapi.aliyuncs.com command to test the connectivity between your on-premises host and the endpoint of the Short Message Service (SMS) API.
If the command times out or does not receive a response, check for blocking policies on your on-premises firewall or routers.
If a response is returned, we recommend that you specify a proper timeout period to prevent request failures caused by improper timeout configurations. For more information, see Configure a timeout period. Sample code:
// Create a RuntimeOptions instance and specify runtime parameters. runtime := &util.RuntimeOptions{} // Configure a timeout period for connection requests. Unit: milliseconds. runtime.ConnectTimeout = tea.Int(10000) // Set the timeout period for connection requests to 10 seconds.
Long processing time of the API request
Cause: The time for processing the API request exceeds the specified read timeout period.
Solution: Extend the timeout period for the API response. For more information, see Configure a timeout period. For example, you can configure the read timeout parameter to extend the read timeout period. Sample code:
// Create a RuntimeOptions instance and specify runtime parameters.
runtime := &util.RuntimeOptions{}
// Configure a timeout period for read requests. Unit: milliseconds.
runtime.ReadTimeout = tea.Int(10000) // Set the timeout period for read requests to 10 seconds.What do I do if compilation fails or the "missing go.sum entry" error message is returned due to dependency version conflicts between different dependency libraries?
The "missing go.sum entry" error message is returned because a dependency to be used does not exist in the go.sum file. The go.mod file in a Go project is used to manage the dependencies of the project. Make sure that no dependency version conflicts exist in the go.mod file. Run the following command on the terminal to update the dependencies of the current module and update the go.mod and go.sum files:
go mod tidyHow do I use an SDK for Go in an existing project?
Open VS Code. In the top navigation bar, choose File > Open Folder. Create and select a project folder or select an existing project folder. In this example, a folder named gosdkproject is created and selected.
In the top navigation bar, choose Terminal > New Terminal. The TERMINAL window appears in the lower part of the console. Run the
go mod init gosdkprojectscommand in the TERMINAL window to initialize the Go project. After the Go project is initialized, a go.mod file is generated in the current project directory. A go.mod file is a module file in a Go project and is used to manage the dependencies and version information of the project.

Go to SDK Center and select the cloud service whose SDK you want to use. Select V2.0 as the SDK version and Go as the programming language. Copy the installation command to the TERMINAL window and press the Enter key.
What do I do if the "MissingRequiredParameter" error is reported when I call an API operation?
In this example, the SendSms operation of the Short Message Service (SMS) service is called.
Go to OpenAPI Portal. Search for the API operation that you want to call.
Check whether the required parameters such as PhoneNumbers and SignName are specified in the constructed request object. In this example, the request object is
SendSmsRequest.Verify that all the required parameters are specified based on the API reference.
Make sure that the values of the required parameters are valid. For example, check whether mobile numbers are specified in valid formats.
Before the SDK sends an API request, the SDK automatically verifies the parameters. If one or more required parameters are not specified, an error such as
MissingRequiredParameteris reported. For example, if the phone_numbers parameter is not specified, the "MissingPhoneNumbers: code: 400" error is reported. In this case, specify the parameter based on the error message.

sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
// The code of the SMS template.
TemplateCode: tea.String("<YOUR_VALUE>"),
// The variables of the SMS template. Example: {\"code\":\"1234\"}.
TemplateParam: tea.String("{\"code\":\"1234\"}"),
// The mobile numbers to which you want to send a text message.
PhoneNumbers: tea.String("<YOUR_VALUE>"),
// The name of the SMS signature.
SignName: tea.String("<YOUR_VALUE>"),
}What do I do if I fail to call an API operation because the operation is not supported in the specified region and the "404 Not Found" message is returned?
Make sure that the region that you select supports the service that you want to access. Find the endpoint of the service on the product homepage in OpenAPI Portal. The following figure shows how to find the endpoint of the SMS service.

Question 8: What do I do if the "go: go.mod file not found in current directory or any parent directory." message is returned when I run the go get command?
The message is returned because the go.mod file cannot be found in the current directory or any of its parent directories when you run the go get command. The go.mod file is used to manage project dependencies and versions. You can run the following command to initialize the go.mod file.
# Initialize a new go.mod file in the current directory and define module names. In most cases, a module name is the URL path to a repository. In this example, the domain name is example.com and the project name is goproject.
go mod init example.com/goprojectChecklist of basic Go exceptions
Error message | Cause | Solution |
Nil pointer dereference | A null pointer is dereferenced, or a method is called on a null pointer. | Before you use the pointer, make sure that the pointer is not nil. You can use a conditional statement or an error handling mechanism to check whether the pointer is nil. |
Invalid memory address or nil pointer dereference | An invalid memory address is accessed, or a null pointer is dereferenced. | Before you access the memory address, make sure that the memory address is valid and memory is allocated to the memory address. You can use a conditional statement or an error handling mechanism to check whether the memory address is valid. |
Timeouts and cancelations | A network request or an operation times out or is canceled. | Before you send a network request or perform a time-consuming operation, configure an appropriate timeout period and cancel the network request or operation based on your business requirements. You can use the context package to manage the timeout period and cancellation operations. |
Technical support
The preceding FAQ and solutions aim to help you better use Alibaba Cloud SDKs. If you encounter other issues, you can contact Alibaba Cloud technical support by using the following method:
If you have questions or feedback, contact Alibaba Cloud technical support in the DingTalk group (ID: 60965016010).