TcaplusDB TDR Table Go SDK Get Started

The preparations for using the Go SDK mainly include:

  1. Prepare the environment;
  2. Create an app;
  3. Create a game zone;
  4. Create a table;
  5. Collect environmental information;
  6. Download SDK;
  7. Configure the development environment.

If the above preparations have been completed, they can be skipped.

1. Prepare the Environment

Refer to Create a Cluster to deploy the TcaplusDB cluster, or apply for the TcaplusDB service.

2. Create an App

Refer to Create an App to create an App.

3. Create A Game Zone

Refer to Create a Game Zone to create a game zone (Zone).

4. Create A Table

Refer to add a Table to add a table.

TDR tables are divided into Generic tables and List tables.

4.1. Generic Table Definition Descriptions

Sample of the Generic table description file: Download.

Content example of the Generic table description file:

<?xml version="1.0" encoding="GBK" standalone="yes" ?>               
<metalib name="table_test" tagsetversion="1" version="1">               
    <struct name="test" version="1" splittablekey="gameid"  primarykey="gameid,itemid,name">               
        <entry name="gameid" type="uint" />                
        <entry name="itemid" type="uint" />               
        <entry name="name" type="string" size="5" />               
        <entry name="typeid" type="uint8"/>               
        <entry name="Data" type="tinyuint" defaultvalue="9"/>               
        <entry name="uname" type="string" size="5" defaultvalue="ab"/>               
        <index name="index_id" column="gameid" />               
    </struct>
</metalib>

Refer to TDR Table for the format description of the TDR table description file.

4.2. List Table Definition Descriptions

Sample of the List table description file: Download.

Content example of the List table description file:

<?xml version="1.0" encoding="GBK" standalone="yes" ?>               
<metalib name="table_test" tagsetversion="1" version="1">               
    <struct name="test" version="1" splittablekey="gameid"  primarykey="gameid,itemid,name" customattr2="TableType=LIST;ListNum=3">               
        <entry name="gameid" type="uint" />                
        <entry name="itemid" type="uint" />               
        <entry name="name" type="string" size="5" />               
        <entry name="typeid" type="uint8"/>               
        <entry name="Data" type="tinyuint" defaultvalue="9"/>               
        <entry name="uname" type="string" size="5" defaultvalue="ab"/>               
        <index name="index_id" column="gameid" />               
    </struct>
</metalib>

Refer to TDR Table for the format description of the TDR table description file.

The TableType = LIST in customattr2 defined by the table is used to identify the list table. Similarly, the ListNum attribute in customattr2 is used to specify how many elements can be stored in a single List at most.

Note: Since the List table has a built-in primarykey field to store the element serial numbers in the List, users can only define up to 7 primarykey fields for the List table.

5. Collect Environmental Information

When using the SDK, it requires some environment related parameters. See the following table for specific parameters and collection methods.

Parameter Value Getting method
Directory server address list Get directory service address list
App ID Get App ID
App access password Get app access password
Game zone ID Get game zone ID
Table name test

6. Download Go SDK

For details about the Go SDK release and download link, see TDR Table SDK Download.

7. Configure the Compilation Development Environment

Environmental dependence Version Description
Go 1.11 and above For the Go language cross-platform, it is recommended to use the version that supports Go mod; Go environment installation https://golang.org/
tsf4g Master Download TDR related dependent tools

7.1 Convert TDR Table XML to Go Code

Download TdrCodeGen tool

python tdr.py table.xml
Get the corresponding table source directory table/table.go
Place table.go in your own go project directory to use

7.2 Compile

Enter the example Directory and click make to compile

# Go parameters
export GO111MODULE=on
export GOPATH:=${GOPATH}:$(shell pwd)/../../../../
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
BINARY_NAME=async

all: build
build:
    $(GOBUILD) -o $(BINARY_NAME) *.go
clean:
    $(GOCLEAN)
    rm -f $(BINARY_NAME)

Example Directory Description:

  • Sync is an example of synchronization + multi-coordination (recommended)
  • Sync2.0 is further optimized and encapsulated based on sync. The synchronization + option mode is simpler to use (recommended)
  • Async is an example of asynchronous mode

8. Use Go SDK

Please refer to the Go SDK Interfaces Descriptions for details

9. FAQ

In the process of using the SDK, if you have questions (such as viewing the SDK version, configuring SDK log printing, upgrading the SDK, etc.), or errors, please refer to "FAQ" and "Meaning and Handling of Error Codes".

  1. FAQ document;

  2. Meaning and Handling of Error Codes document;

results matching ""

    No results matching ""