Gin is a high-performance HTTP web framework written in Golang (Go). Gin has a
Gin allows you to build web applications and microservices in Go. It contains a set of commonly used functionalities (e.g., routing, middleware support, rendering, etc.) that reduce boilerplate code and make it simpler to build web applications.
go get -u github.com/gin-gonic/gin
import "github.com/gin-gonic/gin"
Let’s create a simple web server using Gin. gin.Default()
creates a Gin router with default middleware: logger and
Next, we make a handler using router.GET(path, handle)
, where path
is the relative path, and handle
is the handler function that takes *gin.Context
as an argument. The handler function serves a JSON response with a status of .
Finally, we start the router using router.Run()
that, by default, listens on port .
package mainimport "github.com/gin-gonic/gin"func main() {// Creates a gin router with default middlewarerouter := gin.Default()// A handler for GET request on /examplerouter.GET("/example", func(c *gin.Context) {c.JSON(200, gin.H{"message": "example",}) // gin.H is a shortcut for map[string]interface{}})router.Run() // listen and serve on port 8080}
Gin is an open-source project, you can read more about the API on the Github page.
Free Resources