Query JSON data using Golang (gojsonq package)

Developers often need to consume JSON data from other services and query over it. However, querying JSON data can be time-consuming. Over the past few days, I’ve been working on a Golang package to make querying JSON data easier. The idea and inspiration for this package come from PHP-JSONQ by Nahid Bin Azhar. Let’s start by looking at a sample JSON dataset: Now that we have the JSON data, let’s dive into some examples of how to query it using the package. ...

May 29, 2018 · 2 min · Saddam H

Let’s make a simple todo app with Go

Generally, Go is perfect for building microservices, but that doesn’t mean building a simple MVC app is difficult. Go has built-in support for parsing HTML templates, although we won’t focus on that in this case. First, let’s write the Go code to serve an HTML page and save it in a directory. In this example, let’s create a directory called todoapp and inside it, create a home.tpl file. Paste the HTML content in home.tpl, which will make an HTTP call to our backend application. ...

November 23, 2017 · 5 min · Saddam H

An easy way to validate Go request

When building REST APIs or web applications in Go, one of the essential tasks is validating incoming request data. Having worked on various small to medium-sized projects in Golang—most of which are microservices providing RESTful APIs—I’ve employed several approaches to handle data validation. Among these, there’s one method I frequently rely on. For validating application/json or text/plain requests, I begin by defining a struct type to represent the specific request payload. Then, I implement a Validate method on that struct to encapsulate the validation logic. ...

October 18, 2017 · 2 min · Saddam H

Build RESTful API service in golang using gin-gonic framework

Today, I’m going to build a simple API for a to-do application using the Go programming language. For this, I’ll use Gin, one of Go’s simplest and fastest web frameworks, and Gorm, a powerful and flexible ORM for database operations. To get started, you’ll need to install these packages. Navigate to your workspace directory ($GOPATH/src) and run the following commands: $ go get gopkg.in/gin-gonic/gin.v1 $ go get -u github.com/jinzhu/gorm $ go get github.com/go-sql-driver/mysql In generic crud application we need the API’s as follows: ...

January 20, 2017 · 5 min · Saddam H