Gin-gonic
is a framework based on the httprouter
. We learned about the httprouter
in Chapter 2, Handling Routing for Our REST Services. It is an HTTP multiplexer like Gorilla Mux, but it is faster. Gin
allows a high-level API to create REST services in a clean way. Gin
compares itself with another web framework called martini
. All web frameworks allow us to do a lot more things such as templating and web server design, additional to service creation. Install the Gin
package using the following command:
go get gopkg.in/gin-gonic/gin.v1
Let us write a simple hello world program in Gin
to get familiarized with the Gin
constructs. The file is ginBasic.go
:
package main import ( "time" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() /* GET takes a route and a handler function Handler takes the gin context object */ r.GET("/pingTime", func(c *gin.Context) { // JSON serializer is available on gin context...