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鈥攎ost of which are microservices providing RESTful APIs鈥擨鈥檝e employed several approaches to handle data validation. Among these, there鈥檚 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鈥檓 going to build a simple API for a to-do application using the Go programming language. For this, I鈥檒l use Gin, one of Go鈥檚 simplest and fastest web frameworks, and Gorm, a powerful and flexible ORM for database operations. To get started, you鈥檒l 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鈥檚 as follows: ...

January 20, 2017 路 5 min 路 Saddam H