Golang – Gin Get Started



Gin is a web framework written in Go (Golang). It features a martini-like API with performance that is up to 40 times faster thanks to httprouter. If you need performance and good productivity, you will love Gin. (From Gin web site https://github.com/gin-gonic/gin)


Use Gin is very simple, let’s create simple project and try hello world.

  1. Create a folder under ${GOPATH}/src
  2. Go to above folder
  3. Run go mod init to generate go.mod file
  4. Install gin using go get -u github.com/gin/gonic/gin
cd ${GOPATH}/src
mkdir ginexample
cd ginexample
go mod init
go get -u github.com/gin-gonic/gin

Write simple codes

Let’s write simple codes just return hello world!

Create main.go under above go folder

package main
import (
func main() {
    router := gin.Default()
    router.GET("/", func(c *gin.Context) {
        c.String(http.StatusOK, "Hello World!")

It’s simple codes. This run internal server with 8080 port.


Run above codes with following command.

go run main.go

Access http://localhost:8080 by browser

You can see Hello World! on the browser

Professional Programmer2