Updated on 2024-08-20 GMT+08:00

Setting Up the Go Driver Environment

Go Driver Package

Obtain the package GaussDB-Kernel_Database version number_OS version number_64bit_Go.tar.gz from the release package. Decompress the package to obtain the Go driver source code package.

The Go driver package provided by the database depends on Go 1.13 or later.

Environment Class

  • Configure the Go environment.
  • You need to configure the following parameters in the environment variables:
    • GO111MODULE: Set GO111MODULE to on when installing the Go driver by importing a file online. If you do not want to reconstruct the Go mod project, set GO111MODULE to off and manually download the dependency package. The dependency package must be at the same level as the driver root directory and service code.
    • GOPROXY: When importing data online, you need to configure the path that contains the Go driver package.
    • You can configure other Go environment variables based on your scenario parameters.

    Run the go env command to view the Go environment variable configuration result and check whether the Go version is 1.13 or later.

  • Install the Go driver.
    • Download the Go driver package to the local host. The Go driver repository address is https://open.codehub.huawei.com/OpenSourceCenter/openGauss-connector-go-pq/.
    • Go to the root path of the Go driver code and run the go mod tidy command to download related dependencies. You need to configure GOPATH=${Path for storing the Go driver dependency package} in the environment variables.
    • If the dependencies have been downloaded to the local host, you can add a line "Replace the Go driver package with the local Go driver package address through replace" to go.mod, indicating that all import Go driver packages in the code are stored in the local path and the dependencies are not downloaded from the proxy.

    When you run the go mod tidy command to download dependencies, some of them may be downloaded as an earlier version. If the earlier version has vulnerabilities, you can change the dependency version in the go.mod file and update the dependency to the version after the vulnerability is fixed to avoid risks.

Driver Class

When creating a database connection, you need to enter the database driver name gaussdb.

For details about the Go driver, see Go Driver Compatibility.