TableStoreClient is a client for Tablestore. TableStoreClient provides various methods for you to manage tables and perform read and write operations on a single row or multiple rows. If you want to manage tables and perform read and write operations on a single row or multiple rows in the Wide Column model, you need to initialize a TableStoreClient instance. If you want to manage time series tables, query time series, and read and write time series data in the TimeSeries model, you need to initialize a TimeseriesClient instance.
Preparations
Before you initialize an OTSClient instance, you must configure an AccessKey pair, obtain the endpoint of your Tablestore instance, and install Tablestore SDK for Go.
Configure an AccessKey pair
Obtain the endpoint of a Tablestore instance
Install Tablestore SDK for Go
Initialize a TableStoreClient instance
If you want to use Tablestore SDK for Go to manage tables in the Wide Column model, you must create a TableStoreClient instance and call the operations of the TableStoreClient instance to access Tablestore.
The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. We recommend that you do not hard-code the AccessKey ID and AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account is compromised. In the following examples, the AccessKey pair is configured in the environment variables to verify your identify.
API operation
// Initialize a TableStoreClient instance.
// endPoint: the endpoint that is used to access the Tablestore instance. The endpoint must start with https:// or http://. Example: https://instance.cn-hangzhou.ots.aliyun.com:80.
// accessKeyId: the AccessKey ID that is used to access the Tablestore instance. To obtain an AccessKey ID, you can visit the official website of Alibaba Cloud or contact an administrator.
// accessKeySecret: the AccessKey secret that is used to access the Tablestore instance. To obtain an AccessKey secret, you can visit the official website of Alibaba Cloud or contact an administrator.
// instanceName: the name of the Tablestore instance that you want to access. You can create an instance in the Tablestore console or contact an administrator to obtain the name of an existing instance.
func NewClient(endPoint, instanceName, accessKeyId, accessKeySecret string, options ...ClientOption) *TableStoreClient
Sample code
access_key_id := os.Getenv("OTS_AK_ENV")
access_key_secret := os.Getenv("OTS_SK_ENV")
client := tablestore.NewClient("your_instance_endpoint", "your_instance_name", access_key_id, access_key_secret)
Initialize a TimeseriesClient instance
If you want to use Tablestore SDK for Go to manage tables in the TimeSeries model, you must create a TimeseriesClient instance and call the operations of the TimeseriesClient instance to access Tablestore. The TimeseriesClient instance must be separately initialized for the TimeSeries model.
The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. We recommend that you do not hard-code the AccessKey ID and AccessKey secret into your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account is compromised. In the following examples, the AccessKey pair is configured in the environment variables to verify your identify.
API operation
// Initialize a TimeseriesClient instance.
// endPoint: the endpoint that is used to access the Tablestore instance. The endpoint must start with https:// or http://. Example: https://instance.cn-hangzhou.ots.aliyun.com:80.
// accessKeyId: the AccessKey ID that is used to access the Tablestore instance. To obtain an AccessKey ID, you can visit the official website of Alibaba Cloud or contact an administrator.
// accessKeySecret: the AccessKey secret that is used to access the Tablestore instance. To obtain an AccessKey secret, you can visit the official website of Alibaba Cloud or contact an administrator.
// instanceName: the name of the Tablestore instance that you want to access. You can create an instance in the Tablestore console or contact an administrator to obtain the name of an existing instance.
func NewTimeseriesClient(endPoint, instanceName, accessKeyId, accessKeySecret string , options ...TimeseriesClientOption) *TimeseriesClient
Sample code
access_key_id := os.Getenv("OTS_AK_ENV")
access_key_secret := os.Getenv("OTS_SK_ENV")
timeseriesClient := tablestore.NewTimeseriesClient("your_instance_endpoint", "your_instance_name", access_key_id, access_key_secret)
FAQ
What do I do if the Signature mismatch error is reported when I use Tablestore SDKs?