{"id":46568,"date":"2018-05-09T00:00:00","date_gmt":"2018-05-09T07:00:00","guid":{"rendered":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/blog\/getting-started-with-griddbs-golang-client\/"},"modified":"2025-11-13T12:54:35","modified_gmt":"2025-11-13T20:54:35","slug":"getting-started-with-griddbs-golang-client","status":"publish","type":"post","link":"https:\/\/griddb.net\/en\/blog\/getting-started-with-griddbs-golang-client\/","title":{"rendered":"Getting Started with GridDB&#8217;s Golang Client"},"content":{"rendered":"<h2 id=\"intro\">Introduction<\/h2>\n<p>GridDB has released a <i>database connector<\/i> for Google&#8217;s Go programming language. Like the <a href=\"https:\/\/github.com\/griddb\/python_client\" title=\"GridDB Python GitHub\">Python<\/a> and <a href-\"https:\/\/github.com\/griddb\/python_client\" title=\"GridDB Ruby GitHub Page\">Ruby<\/a> apis for GridDB, it was built using the <a href=\"http:\/\/www.swig.org\/\" title=\"SWIG website\">SWIG<\/a> library. The connector supports versions of Go <b>1.9 or higher<\/b> and can work on CentOS versions <b>6 and 7<\/b>.<br \/>\n<code>Go<\/code> or <a href=\"https:\/\/golang.org\/\" title=\"golang official website\">Golang<\/a> is an open-source programming language developed by Google. It is optimized for parallel and concurrent processing through the use of lightweight threads known as <a href=\"https:\/\/tour.golang.org\/concurrency\/1\" title=\"Concurrency in Go with goroutines\">goroutines<\/a>. This makes Go a high performance programming language that pairs well with a fast, in-memory oriented database like GridDB.<br \/>\nIn this post, we will go through common steps involved in setting up and testing a database connector for GridDB, in this case it will be for our <b>Go client<\/b>.<\/p>\n<style>\nul {\n    padding-left: 36px;\n}\n.toc_container {\n    border: 1px solid #aaa !important;\n    display: table !important;\n    font-size: 95%;\n    margin-bottom: 1em;\n    padding: 20px;\n    width: auto;\n}\n.toc_title {\n    font-weight: 700;\n    text-align: center;\n}\n.toc_container li, .toc_container ul, .toc_container ul li, .toc_container ol li{\n    list-style: outside none none !important;\n}\n<\/style>\n<div id=\"toc-block\" style=\"background: #f9f9f9 none repeat scroll 0 0;border: 1px solid #aaa; padding: 20px; width: auto; display: table;margin-bottom: 1em;\">\n<h5 id=\"toc\">Table of Contents<\/h5>\n<div class=\"toc_container\">\n<ul id=\"toc-list\" style=\"list-style-type: none !important;\">\n<li>1 &nbsp;&nbsp;&nbsp;<a href=\"#setup-go\">Go Client Setup and Installation<\/a><\/li>\n<li style=\"list-style: outside none none !important;\">\n<div class=\"inner-list\">\n<ul style=\"list-style-type: none !important; padding-left: 9px;\">\n<li>1.1 <a href=\"#possible-build-issues\">Possible Build Issues<\/a><\/li>\n<\/ul>\n<\/div>\n<\/li>\n<li>2 &nbsp;&nbsp;&nbsp;<a href=\"#connecting-to-griddb\">Connecting to GridDB with Golang<\/a><\/li>\n<li>3 &nbsp;&nbsp;&nbsp;<a href=\"#schemas-containers\">Creating Row Schemas in Go<\/a><\/li>\n<li>4 &nbsp;&nbsp;&nbsp;<a href=\"#queries\">TQL Queries and Data Management<\/a><\/li>\n<li style=\"list-style: outside none none !important;\">\n<div class=\"inner-list\">\n<ul style=\"list-style-type: none !important; padding-left: 9px;\">\n<li>4.1 <a href=\"#standard-query\">Standard TQL Queries<\/a><\/li>\n<li>4.2 <a href=\"#aggregation-tql\">Aggregation Queries<\/a><\/li>\n<\/ul>\n<\/div>\n<\/li>\n<li>5 &nbsp;&nbsp;&nbsp;<a href=\"#timestamp-and-blob-data\">Handling Timestamp and Binary Data<\/a><\/li>\n<li style=\"list-style: outside none none !important;\">\n<div class=\"inner-list\">\n<ul style=\"list-style-type: none !important; padding-left: 9px;\">\n<li>5.1 <a href=\"#timestamp-type-data\">Timestamp Data<\/a><\/li>\n<li>5.2 <a href=\"#binary-data\">Binary or BLOB Data<\/a><\/li>\n<\/ul style=\"list-style-type: none !important;\">\n<\/div>\n<\/li>\n<li>6 &nbsp;&nbsp;&nbsp;<a href=\"#reference\">References<\/a><\/li>\n<li style=\"list-style: outside none none !important;\">\n<div class=\"inner-list\">\n<ul style=\"list-style-type: none !important; padding-left: 9px;\">\n<li>6.1 <a href=\"#source-code\">Source Code<\/a><\/li>\n<\/ul>\n<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h3 id=\"setup-go\">Go Client Installation &amp; Setup<\/h3>\n<p>Begin by cloning the Github repository for the Go API.<\/p>\n<pre class=\"prettyprint\">\n$ git clone https:\/\/github.com\/griddb\/go_client\n<\/pre>\n<p>To build the Go client on your system, you will need to have the <a href=\"https:\/\/github.com\/griddb\/c_client\" title=\"C client Github Page\">GridDB C client<\/a> built and installed. You can follow this <a href=\"https:\/\/griddb.net\/en\/blog\/using-griddbs-cpythonruby-apis\/#c-intro\">blog post<\/a> on how to set up and test the C client if you are not familiar.<\/p>\n<ul id=\"go-version-note\">\n<li>\n<b>NOTE: <\/b>before you <code>make<\/code> and build the Go client on your system, ensure that you have Golang <b>version 1.9 or higher<\/b>. You can follow instructions on this <a href=\"https:\/\/5wire.co.uk\/install-go-golang-1-9-centos-7\/\" title=\"Installing Go 1.9 on CentOS\">page<\/a> which explains how to get and configure Golang version 1.9.\n<\/li>\n<\/ul>\n<p>Now that you have obtained the source code from Github, you can simply follow the instructions in the <code>README<\/code> on the Go Client&#8217;s <a href=\"https:\/\/github.com\/griddb\/go_client\" title=\"Go client Github repository\">Github page<\/a>.<\/p>\n<h5 id=\"possible-build-issues\">Possible Issues When Building the Go Client<\/h5>\n<p>Occasionally, this error may occur when issuing <code>make<\/code> on the Go client package:<\/p>\n<pre class=\"prettyprint\">\ngo install github.com\/griddb\/go_client\ncan't load package: package github.com\/griddb\/go_client:\n  cannot find package \"github.com\/griddb\/go_client\"\n<\/pre>\n<p>This could likely be due to issues with your <code>GOPATH<\/code> or <code>GODEBUG<\/code>environment variables. A quick correction is to clean the GridDB Go client project directory and then setting them to their proper values.<\/p>\n<pre class=\"prettyprint\">\n$ make clean\n$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:&lt;Path to GridDB c_client bin\/ directory&gt;\n$ export GOPATH=$GOPATH:&lt;Path to go_client directory&gt;\n$ export GODEBUG=cgocheck=0\n$ make\n<\/pre>\n<p><b>NOTE:<\/b> Ensure you always have <code>GODEBUG<\/code> equal to <code>cgocheck=0<\/code>, to prevent  any unexpected runtime errors.<\/p>\n<h3 id=\"connecting-to-griddb\">Connecting to GridDB with Golang<\/h3>\n<p>If you wish to connect to GridDB in a Golang program, simply import the Go API with: <code> import statement ( \"github.com\/griddb\/go_client\" )<\/code>. The name of the GridDB package for Golang is <code>griddb_go<\/code>.<br \/>\nFrom there you can obtain a <code>StoreFactoryInstance<\/code> from the GridDB library and connect it to your GridDB cluster with the factory instance&#8217;s <code>.GetStore()<\/code> method. The parameters you give this method are a <code>map[string]interface{}{}<\/code> object (equivalent of a <i>HashMap or Python dictionary<\/i> with <i>string-keys<\/i>). The keys are simply the configuration fields you want to specify to connect to GridDB.<br \/>\nNote that the port <b>must be specified as an integer<\/b> while all the other database configuration values like host or cluster name can be strings.<\/p>\n<pre class=\"prettyprint\">\npackage main\nimport (\n\t\"github.com\/griddb\/go_client\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\nfunc main(){\n\tfactory := griddb_go.StoreFactoryGetInstance() \/\/Get a GridStoreFactory instance\n        \/\/The 'notificationPort' value to connect to GridDB must be an integer\n        \/\/when using the StoreFactory.GetStore() method to connect to GridDB\n        \/\/Read notification-port from command-line\n        \/\/Parse port reading to integer\n\tport, err := strconv.Atoi(os.Args[2])\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(2)\n\t}\n        \/\/Connect to GridDB cluster\n        \/\/Note that port must be an integer\n        gridstore := factory.GetStore(map[string]interface{}{\n                \"host\": os.Args[1], \/\/ \"239.0.0.1\"\n                \"port\": os.Args[2], \/\/ 31999\n                \"cluster_name\": os.Args[3], \/\/\"defaultCluster\"\n                \"user\": os.Args[4], \/\/ \"admin\"\n                \"password\": os.Args[5], \/\/ \"admin\"\n                \/\/\"notification_member\": os.Args[6],\n                \/\/\"notification_provide\": os.Args[7],\n        })\n        \/\/Close access to GridDB\n        gridstore.Close(0)\n        \/\/Note that you must specify an integer flag when using the .Close() function call\n}\n<\/pre>\n<h3 id=\"schemas-containers\">Creating Schemas and Containers<\/h3>\n<p>Schemas for containers and rows can be created using the <a href=\"https:\/\/golang.org\/ref\/spec#Interface_types\" title=\"Documentation on Golang interfaces\">interface<\/a> types in Golang.<br \/>\nYou can simply use a <i>two-dimensional array<\/i> of interfaces to map the column types for your container. From there you can create a container schema (<code>ContainerInfo Type<\/code>) by using the <code>StoreFactory.CreateContainerInfo()<\/code> method. You can use and insert these <i>schemas<\/i> to create containers.<br \/>\n<b>Rows<\/b> can be modeled as interface arrays ( <code>[]interface{}<\/code> ). To create a row just create an interface array and have each index&#8217;s value map to the corresponding type it is supposed to store in the container.<br \/>\nFor example, if in a container the second column stores an integer named <code>'count'<\/code>, then the value <code>3<\/code> from <i>index 1<\/i> in the array <code>row := []interface{}{\"A_1\",3,true}<\/code> would be mapped to the <code>'count'<\/code> column.<\/p>\n<pre class=\"prettyprint\">\n\/\/Container schema for our timeseries container\n\/\/The first column is always the row-key\nrow_schema := [][]interface{}{\n\t\t{\"timestamp\",griddb_go.TYPE_TIMESTAMP},\n\t\t{\"water_temperature\",griddb_go.TYPE_FLOAT},\n\t\t{\"turbidity\",griddb_go.TYPE_FLOAT},\n\t\t{\"depth\",griddb_go.TYPE_FLOAT},\n\t\t{\"wave_height\",griddb_go.TYPE_FLOAT},\n\t\t{\"wave_period\",griddb_go.TYPE_FLOAT},\n\t\t{\"battery_life\",griddb_go.TYPE_FLOAT},\n\t\t{\"beach_name\",griddb_go.TYPE_STRING}}\ntimeseries_name := \"water_monitor_ts_2\" \/\/Name for our container\n\/\/Create a container info to use to insert containers into GridDB\ncontainerInfo, err := griddb_go.CreateContainerInfo(timeseries_name,\n                        row_schema,\n                        griddb_go.CONTAINER_TIME_SERIES,\n                        true)\ntimeseries := gridstore.PutContainer(containerInfo,false)\n\/\/Use an interface array to create and insert rows\nrow := []interface{}{time.Now().UTC(),16.2,1.26,1.514,0.147,4.0,11.7,\"Calumet Beach\"}\n\/\/ You can also initialize an empty row with ( row := make([]interface{},8) )\n\/\/Insert row into Timeseries container\nerr = timeseries.Put(row)\n<\/pre>\n<p>You can also obtain a <b>Row<\/b> with a simple call to the <code>.Get()<\/code> method on the container with its <b>row-key<\/b>. As mentioned before, a row is just an array of generic Golang <i>interfaces<\/i>, all one needs to do to access the column value they want to retrieve is to reference the <i>row-index<\/i> of the column.<br \/>\nFor example, let us have a container with a column <code>'longitude'<\/code> of type float that is the <i>fourth<\/i> column in the container&#8217;s schema. When you retrieve a row from this container, to access the <b>longitude<\/b> column all that needs to be done to access the fields is access <b>index 4<\/b>.<br \/>\nYou can also <b>remove<\/b> rows in a container by row-key as well.<\/p>\n<pre class=\"prettyprint\">\n \/\/Schema of our collection container\nschema, err := griddb_go.CreateContainerInfo(collection_name,[][]interface{}{\n\t\t{\"sid\",griddb_go.TYPE_STRING},\n\t\t{\"name\",griddb_go.TYPE_STRING},\n\t\t{\"type\",griddb_go.TYPE_STRING},\n\t\t{\"latitude\",griddb_go.TYPE_DOUBLE},\n\t\t{\"longitude\",griddb_go.TYPE_DOUBLE},\n\t\t{\"installation\",griddb_go.TYPE_TIMESTAMP}},\n\t\tgriddb_go.CONTAINER_COLLECTION,\n\t\ttrue)\ncollection, err := gridstore.PutContainer(schema,false)\n\/\/ (snip)\n\/\/Find a row in the collection container with row-key ('sid') \"W_1003\"\nretrieved, err := collection.Get(\"W_1003\")\nif len(retrieved) > 0 {\n                \/\/Access and display longitude column of row (is column 4 in row)\n                fmt.Printf(\"Longitude value of row with row-key %s is %fn\",\"W_1003\",retrieved[4]\n}\n\/\/We can also remove the \"W_1003\" row by calling .remove()\ncollection.Remove(\"W_1003\")\n\/\/Attempt to access row again, this should return an empty row (an empty array) if the removal was successful\nattempt, err := collection.Get(\"W_1003\")\nif len(attempt) == 0 {\n                fmt.Printf(\"Row with key %s removed successfullyn\",\"W_1003\")\n}\n<\/pre>\n<h3 id=\"queries\">Querying and Retrieving Data<\/h3>\n<p>Once you have your containers populated with data and inserted into GridDB, you are ready to query and fetch your data. Similar to the Python or Java APIs, all you need to is to construct a <b>Query object<\/b>  (or <code>griddb_go.Query<\/code> type) with the TQL query you would like to issue to your container. Once that is done, simply <b>fetch<\/b> the query&#8217;s results and store it in a <code>griddb_go.RowSet<\/code> object.<\/p>\n<ul>\n<li>\n<b>Note: <\/b>, if you want to select specific rows to update, you must set the <i>commit-mode<\/i> of the container you are trying update to <i>false<\/i>.\n<\/li>\n<\/ul>\n<p>Once you have finished with updating row values using either <code>griddb_go.Container.Put()<\/code> or <code>griddb_go.RowSet.Update()<\/code> methods, you can <code>Commit()<\/code> the changes.<\/p>\n<h4 id=\"standard-query\">Standard TQL Query<\/h4>\n<pre class=\"prettyprint\">\n\/\/Set commit-mode to false so you can update the rows\ncollection.SetAutoCommit(false)\n\/\/Search for a row with row-key that ends in '2' and has a column value of 'weather' in the type column\nquery,err := collection.Query(\"select * WHERE CHAR_LENGTH(sid) = 6 AND sid LIKE 'W%2' AND LOWER(type) = 'weather'\")\n\/\/Fetch the rows and make them available for update\nrowSet,err := query.Fetch(true)\nfor rowSet.HasNext(){\n        \/\/Retrieve and iterate through the rowset row-by-row\n\trrow, err := rowSet.NextRow()\n\tif err != nil{\n\t\tfmt.Println(\"Error retrieving row\")\n\t}\n        \/\/Update the fourth column value of the row\n\trrow[4] = -88.0\n        \/\/Save updated row back to the rowSet\n\trowSet.Update(rrow)\n}\n\/\/Commit and save the updated RowSet back to the container\ncollection.Commit()\n<\/pre>\n<h4 id=\"aggregation-tql\">Aggregation TQL<\/h4>\n<p>You can also use <i>TQL<\/i> to create and issue aggregation queries. The methods of performing and fetching <code>griddb_go.AggregationResult<\/code> from containers is fairly similar to the Python API. Once you have obtained the <b>RowSet<\/b> fetched from your query, instead of using <code>rowSet.NextRow()<\/code> we simply change it to <code>.NextAggregation()<\/code>. With that <code>AggregationResult<\/code> object, we use the <code>.Get()<\/code> to get the type of number we need.<\/p>\n<pre class=\"prettyprint\">\ncolumn := \"turbidity\"\naggQuery, err := timeseries.Query(fmt.Sprintf(\"SELECT TIME_AVG(%s)\",column)) \/\/Get the time-weighted average of all turbidity values in our container\nif err != nil {\n\tfmt.Printf(\"Failed to issue query to timeseries container %sn\",container_name)\n\tfmt.Println(err)\n\tos.Exit(2)\n}\naggRowSet, err := aggQuery.Fetch(false) \/\/Issue query and fetch results\nif err != nil {\n\tfmt.Printf(\"Error retrieving query results from timeseries container %sn\",container_name)\n\tfmt.Println(err)\n\tos.Exit(2)\n}\nfor aggRowSet.HasNext(){\n\taggregation, err := aggRowSet.NextAggregation() \/\/Get the aggregation result from the rowset.\n\tif err != nil {\n\t\tfmt.Println(\"Failed to get aggregation result!\")\n\t} else {\n\t\tavg, err := aggregation.Get(griddb_go.TYPE_DOUBLE) \/\/Get the aggregation result's numerical value\n\t\tif err != nil {\n\t\t\tfmt.Printf(\"Error parsing aggreagtion resultn\")\n\t\t}\n\t\tfmt.Printf(\"The time average for the %s column in the %s container is %fn\",column,container_name,avg)\n\t}\n}\n<\/pre>\n<h3 id=\"timestamp-and-blob-data\">Handling Timestamp and Binary Data<\/h3>\n<h4 id=\"timestamp-type-data\">Timestamp Data<\/h4>\n<p>The Golang client for GridDB provides the same offerings as the other API clients (Python, C) for timestamp manipulation. An important thing to note is that in GridDB, to insert a <i>time or date<\/i> value into a GridDB container, the value has to able to be cast to a <code>Time.time<\/code> type in Golang.<br \/>\nWhat this means is that one <b>cannot<\/b> insert timestamp values as pure <i>numerical value<\/i>. If one does, this means that the call to <code>container.Put(row)<\/code> will fail if the timestamp value is in a <i>row-key<\/i> column and the data will not be inserted into the container.<br \/>\nAnother thing to <b>NOTE<\/b> is that the GridDB timestamps have a <i>precision<\/i> in <i>milliseconds<\/i>.<br \/>\nA way to convert the GridDB timestamp number into <i>type<\/i> <code>time.Time<\/code> is to convert the timestamp number into <i>nanoseconds<\/i> and use <code>time.Unix()<\/code> to convert it into the time Type.<\/p>\n<pre class=\"prettyprint\">\nimport (\n     \"time\"\n     \"github.com\/griddb\/go_client\"\n)\n\/\/ (snip)\n\/\/A way to express the current time as a time Type in Golang\nnow := time.Now().UTC() \/\/This has less precision than GridDB TimestampUtils\n\/\/ GridDB method of getting the current time as a number\nnow_ts :=  time.Unix(griddb_go.TimestampUtilsCurrent() * 1000000)\/\/ The number is then converted into a UTC time\n\/\/ Converting GridDB to Time.time values allows for precision and lowers the chance that\n\/\/ a row will inadvertently replace another row with the same row-key.\nrow := []interface{}{now_ts.UTC(),true,5.6}\nerr = timeseries.Put(row)\n<\/pre>\n<h4 id=\"binary-data\">Binary or Blob Data<\/h4>\n<p>In GridDB, binary or <b>BLOB<\/b> data, can be represented as <code>bytearray<\/code>. In the case of having to read image data or large buffers simply allocate an empty <i>byte array<\/i> or <code>[] byte<\/code>.<br \/>\nThe function below <b>parseBlob<\/b> reads the data from an image into a <b>bytearray<\/b>.<\/p>\n<pre class=\"prettyprint\">\nfunc parseBlob(filename string) (blob []byte){\n\tfile, err := os.Open(filename) \/\/Open image file\n\tif err != nil {\n\t\tfmt.Printf(\"Error opening file %sn\",filename)\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\tdefer file.Close()\n\tfileInfo, _ := file.Stat() \/\/Get meta-information related to the image file\n\tvar size int64 = fileInfo.Size() \/\/Obtain file size\n\toutputStream := make([]byte,size) \/\/Allocate a byte array that is the size of the image's data\n\tbuffer := bufio.NewReader(file) \/\/Create a file reader for reading byte data from image file\n\t_, err = buffer.Read(outputStream) \/\/Read image file's data into output byte array\n\treturn outputStream\n}\n<\/pre>\n<p>We can then use the data from <code>parseBlob<\/code> to be the values of our <i>BLOB<\/i> columns<\/p>\n<pre class=\"prettyprint\">\nimage_blob := parseBlob(\"liveimage1.jpg\") \/\/Get bytearray for image file's data\nnow := time.Now().UTC() \/\/Obtain current time\n\/\/Create a Row containing our BLOB data (byte array) and insert it into Timeseries container\nfirst_row := []interface{}{now,\"Bright Sky\",500,\"liveimage1.jpg\",image_blob)\nerr = timeseries.Put(first_row)\nblob :=  []byte{65, 66, 67, 68, 69, 70, 71, 72, 73, 74} \/\/Create Blob as a simple byte array\nthird_row := []interface{}{time.Now().UTC(),\"Generic\",10,\"NULL\",blob}\n\/\/Create and insert GridDB row containing smaller byte array\nerr = timeseries.Put(third_row)\n<\/pre>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>It should now be quite easy to connect and manage your GridDB cluster using Go. With all the various utilities offered by the GridDB Go client, storing data and developing high-performance Go applications with GridDB should now be a rather fun proposition.<\/p>\n<h4 id=\"reference\">Reference<\/h4>\n<ul>\n<li>\n<p>Golang <a href=\"https:\/\/dl.google.com\/go\/go1.10.1.linux-amd64.tar.gz\" title=\"Download Golang 1.9 for Linux\">version 1.9.2 linux\/amd64<\/a> was used for this post on a <b>CentOS 7.3<\/b> operating system.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/griddb\/griddb_nosql\/releases\/download\/v3.0.1\/griddb_nosql-3.0.1-1.linux.x86_64.rpm\" title=\"Download GridDB CE\">GridDB Community Edition 3.0.1<\/a> was used as the GridDB database for this tutorial<\/p>\n<\/li>\n<li>\n<p>The source code for the GridDB Go client can be found on the <a href=\"https:\/\/github.com\/griddb\/go_client\" title=\"Go client Github Page\">official Github repository<\/a>.<\/p>\n<\/li>\n<li>\n<p>This <a href=\"http:\/\/www.griddb.org\/go_client\/GoAPIReference.htm\" title=\"Go API Reference\">reference page<\/a> lists all the objects and resources from GridDB that can be accessed with the Go client<\/p>\n<\/li>\n<li>\n<p>Once the Go library for GridDB is built, all the methods and attributes used in the <b>griddb_go<\/b> package can be found in the <code>src\/griddb_go.go<\/code> files.<\/p>\n<\/li>\n<li>\n<p>If you want to learn more about how to use Golang, check out the <a href=\"https:\/\/golang.org\/doc\/\" title=\"Golang official documentation page\">official documentation<\/a>.<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"source-code\">Source Code<\/h4>\n<p>All the source code used in this post can be downloaded below.<\/p>\n<ul id=\"source-code-sample\">\n<li><a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/griddb.net\/en\/download\/24823\/?tmstv=1775654263\" rel=\"nofollow\" id=\"download-link-24823\" data-redirect=\"false\" >\n\tgo_samples.zip\t(563 downloads\t)\n<\/a>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction GridDB has released a database connector for Google&#8217;s Go programming language. Like the Python and Ruby apis for GridDB, it was built using the SWIG library. The connector supports versions of Go 1.9 or higher and can work on CentOS versions 6 and 7. Go or Golang is an open-source programming language developed by [&hellip;]<\/p>\n","protected":false},"author":123,"featured_media":25800,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[121],"tags":[],"class_list":["post-46568","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Getting Started with GridDB&#039;s Golang Client | GridDB: Open Source Time Series Database for IoT<\/title>\n<meta name=\"description\" content=\"Introduction GridDB has released a database connector for Google&#039;s Go programming language. Like the Python and Ruby apis for GridDB, it was built using\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting Started with GridDB&#039;s Golang Client | GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"og:description\" content=\"Introduction GridDB has released a database connector for Google&#039;s Go programming language. Like the Python and Ruby apis for GridDB, it was built using\" \/>\n<meta property=\"og:url\" content=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/\" \/>\n<meta property=\"og:site_name\" content=\"GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/griddbcommunity\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-09T07:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-13T20:54:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/griddb.net\/wp-content\/uploads\/2018\/05\/blog_title_25.png\" \/>\n\t<meta property=\"og:image:width\" content=\"870\" \/>\n\t<meta property=\"og:image:height\" content=\"490\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Joshua Pascascio\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:site\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joshua Pascascio\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/\"},\"author\":{\"name\":\"Joshua Pascascio\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/ca72185e9a3778df765a76313f789fd8\"},\"headline\":\"Getting Started with GridDB&#8217;s Golang Client\",\"datePublished\":\"2018-05-09T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:54:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/\"},\"wordCount\":1257,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2018\/05\/blog_title_25.png\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/\",\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/\",\"name\":\"Getting Started with GridDB's Golang Client | GridDB: Open Source Time Series Database for IoT\",\"isPartOf\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2018\/05\/blog_title_25.png\",\"datePublished\":\"2018-05-09T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:54:35+00:00\",\"description\":\"Introduction GridDB has released a database connector for Google's Go programming language. Like the Python and Ruby apis for GridDB, it was built using\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage\",\"url\":\"\/wp-content\/uploads\/2018\/05\/blog_title_25.png\",\"contentUrl\":\"\/wp-content\/uploads\/2018\/05\/blog_title_25.png\",\"width\":870,\"height\":490},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website\",\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/\",\"name\":\"GridDB: Open Source Time Series Database for IoT\",\"description\":\"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL\",\"publisher\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization\",\"name\":\"Fixstars\",\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"contentUrl\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"width\":200,\"height\":83,\"caption\":\"Fixstars\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/griddbcommunity\/\",\"https:\/\/x.com\/GridDBCommunity\",\"https:\/\/www.linkedin.com\/company\/griddb-by-toshiba\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/ca72185e9a3778df765a76313f789fd8\",\"name\":\"Joshua Pascascio\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/872ef8be79cb5117c256feb4c279ac41b954bfba599d647db925185c449aff1c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/872ef8be79cb5117c256feb4c279ac41b954bfba599d647db925185c449aff1c?s=96&d=mm&r=g\",\"caption\":\"Joshua Pascascio\"},\"url\":\"https:\/\/griddb.net\/en\/author\/joshua\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting Started with GridDB's Golang Client | GridDB: Open Source Time Series Database for IoT","description":"Introduction GridDB has released a database connector for Google's Go programming language. Like the Python and Ruby apis for GridDB, it was built using","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/","og_locale":"en_US","og_type":"article","og_title":"Getting Started with GridDB's Golang Client | GridDB: Open Source Time Series Database for IoT","og_description":"Introduction GridDB has released a database connector for Google's Go programming language. Like the Python and Ruby apis for GridDB, it was built using","og_url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/","og_site_name":"GridDB: Open Source Time Series Database for IoT","article_publisher":"https:\/\/www.facebook.com\/griddbcommunity\/","article_published_time":"2018-05-09T07:00:00+00:00","article_modified_time":"2025-11-13T20:54:35+00:00","og_image":[{"width":870,"height":490,"url":"https:\/\/griddb.net\/wp-content\/uploads\/2018\/05\/blog_title_25.png","type":"image\/png"}],"author":"Joshua Pascascio","twitter_card":"summary_large_image","twitter_creator":"@GridDBCommunity","twitter_site":"@GridDBCommunity","twitter_misc":{"Written by":"Joshua Pascascio","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#article","isPartOf":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/"},"author":{"name":"Joshua Pascascio","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/ca72185e9a3778df765a76313f789fd8"},"headline":"Getting Started with GridDB&#8217;s Golang Client","datePublished":"2018-05-09T07:00:00+00:00","dateModified":"2025-11-13T20:54:35+00:00","mainEntityOfPage":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/"},"wordCount":1257,"commentCount":0,"publisher":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2018\/05\/blog_title_25.png","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/","url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/","name":"Getting Started with GridDB's Golang Client | GridDB: Open Source Time Series Database for IoT","isPartOf":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2018\/05\/blog_title_25.png","datePublished":"2018-05-09T07:00:00+00:00","dateModified":"2025-11-13T20:54:35+00:00","description":"Introduction GridDB has released a database connector for Google's Go programming language. Like the Python and Ruby apis for GridDB, it was built using","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/getting-started-with-griddbs-golang-client\/#primaryimage","url":"\/wp-content\/uploads\/2018\/05\/blog_title_25.png","contentUrl":"\/wp-content\/uploads\/2018\/05\/blog_title_25.png","width":870,"height":490},{"@type":"WebSite","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#website","url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/","name":"GridDB: Open Source Time Series Database for IoT","description":"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL","publisher":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#organization","name":"Fixstars","url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/","url":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","contentUrl":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","width":200,"height":83,"caption":"Fixstars"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/griddbcommunity\/","https:\/\/x.com\/GridDBCommunity","https:\/\/www.linkedin.com\/company\/griddb-by-toshiba"]},{"@type":"Person","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/ca72185e9a3778df765a76313f789fd8","name":"Joshua Pascascio","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/872ef8be79cb5117c256feb4c279ac41b954bfba599d647db925185c449aff1c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/872ef8be79cb5117c256feb4c279ac41b954bfba599d647db925185c449aff1c?s=96&d=mm&r=g","caption":"Joshua Pascascio"},"url":"https:\/\/griddb.net\/en\/author\/joshua\/"}]}},"_links":{"self":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/posts\/46568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/users\/123"}],"replies":[{"embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/comments?post=46568"}],"version-history":[{"count":1,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/posts\/46568\/revisions"}],"predecessor-version":[{"id":51259,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/posts\/46568\/revisions\/51259"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/media\/25800"}],"wp:attachment":[{"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/media?parent=46568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/categories?post=46568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/griddb.net\/en\/wp-json\/wp\/v2\/tags?post=46568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}