Connect Go Applications Without a Wallet (TLS) Using TLS
You can connect Go applications to your Autonomous AI 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).
Enable TLS on Autonomous AI Database and Obtain Connection String
To run a Go application without a wallet using TLS, enable the Autonomous AI Database instance for TLS connections and obtain a connection string to contact the database from the Go application.
-
Determine if your Autonomous AI 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.
If your instance requires Mutual TLS authentication, allow TLS connections on your Autonomous AI Database instance. See Update your Autonomous AI Database Instance to Allow both TLS and mTLS Authentication for details.
-
Obtain an Autonomous AI Database service connection string to access the database as follows:
-
On the Oracle Cloud Infrastructure Console, click Database connection.
-
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).
-
Copy the connection string for the database service you want to use with your application.
See View TNS Names and Connection Strings for an Autonomous AI Database Instance for more information.
-
Run Go Application Without a Wallet Using TLS
The following section describes the steps to run a Go application on an Autonomous AI Database instance.
-
Obtain the connection string, as described in Enable TLS on Autonomous AI Database and Obtain Connection String.
-
In your Go application, set the following parameters to connect to an Autonomous AI Database instance:
-
password: Specifies the database user password. -
user: Specifies the database user. -
libDir: Single directory where you unzip the Oracle Instant Client compressed package. -
connectString: Use the connection string you obtained from the previous step to connect using the preferred database service name.
To run a Go application using the
godrordriver, you must first import thegodrorpackage.Following is a sample code in the Go Application which enables you to connect to an Autonomous AI Database:
package main import ( "database/sql" "fmt" _ "github.com/godror/godror" ) func main() { connectToADb() } func connectToADb() { fmt.Println("Connecting to Oracle Autonomous AI 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 AI Database.
-