How To Setup Oracle With Golang
This will be a fairly simple setup thanks to the steps you’ve hopefully already finished from my previous post on how to setup Oracle for OS X.
Setup pkg-config
We will be setting up the package config file (oci8.pc
) so Golang can find the headers needed to compile the oracle driver I’ve found.
The file goes somewhere in the $PKG_CONFIG_PATH
, but I’m not sure what that is because on my own system that was an empty enviroment variable. According to the instructions from the package I wanted to use, a path in the default $PKG_CONFIG_PATH
is /usr/local/lib/pkgconfig/
.
Here is my file (Which will likely work for you unedited if you followed my previous post):
$ cat /usr/local/lib/pkgconfig/oci8.pc
prefix=/usr/local/Cellar/instantclient-sdk/11.2.0.4.0/lib/
version=11.2
build=client64
libdir=${prefix}
includedir=${prefix}/sdk/include
Name: oci8
Description: Oracle database engine
Version: ${version}
Libs: -L${libdir} -lclntsh
Libs.private:
Cflags: -I${includedir}
Check pkg-config
To make sure everything works as we wanted, make sure oci8 is a package config pkg-config
recognizses.
$ pkg-config --list-all | grep oci8
oci8 oci8 - Oracle database engine
go get …
And now you can comfortably get either one of the Golang oracle drivers I found.
$ go get gopkg.in/rana/ora.v3
$ go get github.com/mattn/go-oci8
From here
If everything went as planned your package should have installed successfully.
If you want to also have this in Python, which is even easier than this, go check out the other post I have on setting up Oracle with Python.