Before You Begin
This 15-minute tutorial shows you how to connect a Go application to Oracle Database Cloud Service and how to deploy your application to Oracle Application Container Cloud Service.
Background
Oracle Application Container Cloud Service lets you deploy Go, Java Platform, Standard Edition (Java SE), Node.js, PHP, Python, Ruby, and Enterprise Edition (Java EE) applications to the Oracle Cloud.
This tutorial provides you a sample application that creates a connection to Oracle Database Cloud Service. To create the connection it uses the environment variables DBAAS_USER_NAME, DBAAS_USER_PASSWORD,
and DBAAS_DEFAULT_CONNECT_DESCRIPTOR
that are provided by Oracle Application Container Cloud Service. The environment variables are created when you create the service binding. In this tutorial, you create the service binding by using a deployment.json
file.
What Do You Need?
- Access to an instance of Oracle Application Container Cloud Service
- An Oracle Database Cloud Service Instance. See Creating an Oracle Database Cloud Service Instance for Oracle Integration Cloud
- The instant client package-Basic Light instantclient-basiclite-linux.x64-12.2.0.1.0.zip
- The instant client package-SDK instantclient-sdk-linux.x64-12.2.0.1.0.zip
- The Debian libaio package libaio1_0.3.110-1_amd64.deb
- The oracle-db.go file
Create a Go Project
In this section, you put together all the elements that are required to connect your Go application to Oracle Database Cloud Service.
- Create the
go-oracle-db/oracle
path directory in your local system. - In the
oracle
directory, extract the content of theinstantclient-basiclite-linux.x64-12.2.0.1.0.zip
andinstantclient-sdk-linux.x64-12.2.0.1.0.zip
files. - Copy the
oracle-db.go
andlibaio1_0.3.110-1_amd64.deb
files to thego-oracle-db
directory. - In the
oracle-db\Oracle\instantclient_12_2
directory, create theoci8.pc
file and add the following content:prefixdir=/u01/app/Oracle/instantclient_12_2 libdir=${prefixdir} includedir=${prefixdir}/sdk/include Name: OCI Description: Oracle database driver Version: 12.2 Libs: -L${libdir} -lclntsh Cflags: -I${includedir}
Prepare the Application for Cloud Deployment
- In the
go-oracle-db
directory, create themanifest.json, deployment.json,
andstart.sh
files. - Open the
manifest.json
file in a text editor and add the following content:{ "runtime": { "majorVersion": "1.8.3" }, "command": "sh start.sh", "notes": "Go Application Sample" }
- Open the
deployment.json
file in a text editor and add the following content. Replace the placeholders with your information:{ "services": [{ "name": "Name of your Oracle Database Cloud Service instance", "type": "DBAAS", "username": "Your database user name", "password": "Your database password" }] }
- Open the
start.sh
file in a text editor and add the following content:# Extract LIBAOI libs from Debian package (into ./lib/x86_64-linux-gnu) dpkg-deb -R libaio1_0.3.110-1_amd64.deb ${APP_HOME} export PKG_CONFIG_PATH=${APP_HOME}/Oracle/instantclient_12_2 # Add OCI and LIBAIO to shared library path export LD_LIBRARY_PATH=${APP_HOME}/Oracle/instantclient_12_2:${APP_HOME}/lib/x86_64-linux-gnu # Finalize OCI installation by creating required softlink ln -s -f ${APP_HOME}/Oracle/instantclient_12_2/libclntsh.so.12.1 ${APP_HOME}/Oracle/instantclient_12_2/libclntsh.so ln -s -f ${APP_HOME}/Oracle/instantclient_12_2/libocci.so.12.1 ${APP_HOME}/Oracle/instantclient_12_2/libocci.so # Install Go dependencies go get github.com/mattn/go-oci8 go get github.com/ant0ine/go-json-rest/rest # Launch the application go run oracle-db.go
- Create a
zip
file with the content of thego-oracle-db
directory.
Deploy the Application to Oracle Application Container Cloud Service
- Open the Oracle Application Container Cloud Service console.
- In the Applications list view, click Create Application and select Go.
- In the Application section, enter a name for your application and click Browse.
- On the File Upload dialog box, select the
.zip
file that you created in the previous section and click Open. - Keep the default values in the Instances and Memory fields.
- Click More options, and then click Browse next to Deployment Configuration.
- On the File Upload dialog box, select the
deployment.json
file that you created in the previous section and click Open. - Click Create.
- Wait until the application is created. The URL is enabled when the creation is completed.
- Click the URL of your application.
Description of the illustration go-app-response.png
Want to Learn More?
- Oracle Application Container Cloud Service: Get Started in the Oracle Help Center
- Go website golang.org