Connect Go Applications Without a Wallet (TLS) Using TLS

You can connect Go applications to your Autonomous Database instance without a wallet using TLS.

Connecting a Go application without a wallet (TLS) provides security for authentication and encryption, and security is enforced using client credentials (by providing a username and password).

Follow this step to connect your Go application to an Autonomous Database instance without a wallet (TLS):

Topics

Enable TLS on Autonomous Database and Obtain Connection String

To run a Go application without a wallet using TLS, enable the Autonomous Database instance for TLS connections and obtain a connection string to contact the database from the Go application.

  1. Determine if your Autonomous Database instance is enabled for TLS connections.

    If the instance is enabled for TLS connections, in the Network area on the Console the Mutual TLS (mTLS) authentication field shows: Not Required:

    Description of adb_mutual_tls_not_required.png follows
    Description of the illustration adb_mutual_tls_not_required.png

    If your instance requires Mutual TLS authentication, allow TLS connections on your Autonomous Database instance. See Update your Autonomous Database Instance to Allow both TLS and mTLS Authentication for details.

  2. Obtain an Autonomous Database service connection string to access the database as follows:
    1. On the Oracle Cloud Infrastructure Console, click Database connection.
    2. Select TLS in the Database Connection dialog box, under Connection Strings, in the TLS Authentication drop-down list.

      Note:

      You must select TLS in the TLS Authentication drop-down to obtain the TLS connection strings before you copy a connection string (when the value is Mutual TLS the connection strings have different values and do not work with TLS connections).
    3. Copy the connection string for the database service you want to use with your application.

Run Go Application Without a Wallet Using TLS

The following section describes the steps to run a Go application on an Autonomous Database instance.

  1. Obtain the connection string, as described in Enable TLS on Autonomous Database and Obtain Connection String.
  2. In your Go application, set the following parameters to connect to an Autonomous Database instance:
    • password: Specifies the database user password.
    • user: Specifies the database user.
    • libDir: Single directory where you unzip the Oracle Instant Client zip package.
    • connectString: Use the connection string you obtained from the previous step to connect using the desired database service name.

    To run a Go application using the godror driver, you must first import the godror package.

    Following is a sample code in the Go Application which enables you to connect to an Autonomous Database:

    package main
    
    import (
        "database/sql"
        "fmt"
    
        _ "github.com/godror/godror"
    )
    
    func main() {
        connectToADb()
    }
    
    func connectToADb() {
        fmt.Println("Connecting to Oracle Autonomous database !!!")
        db, err := sql.Open("godror", `user="admin" password="password" 
        connectString="tcps://adb.ap-mumbai-1.oraclecloud.com:1522/abcd_xxxx_medium.adb.oraclecloud.com?wallet_location=/Users/user/tool/wallet_DB/"
        libDir="/home/user/tool/instantclient_19_8/"`)
        if err != nil {
            fmt.Println(err)
            return
        }
        defer db.Close()
    
        rows, err := db.Query("select 'hello' from dual")
        if err != nil {
            fmt.Println("Error running query")
            fmt.Println(err)
            return
        }
        defer rows.Close()
    
        var resData string
        for rows.Next() {
    
            rows.Scan(&resData)
        }
        fmt.Printf("The response is: %s\n", resData)
    }
    

    This code will return records retrieved from the Autonomous Database.