Building Gin environment


To use Gin, you need to install Go, so please install that.

To install, select the installation method that suits your environment from the official website.

create gin environment

  1. Create go.mod for module management. Create a working directory and run go mod init
mkdir gin
cd gin
go mod init hello
  1. To use Gin, install Gin using GoCLI.
go get -u
  1. Let’s actually write the code
vi main.go


package main

import ""

func main() {
  r := gin.Default()
  r.GET("/hello", func(c *gin.Context) {
    c.JSON(200, gin.H{ "message": "hello" })
r.Run() // listen and serve on (for windows "localhost:8080")

The final file structure is as follows.


After creating the environment, run the following command to check if it can be started.

go run main.go

If the command succeeds, Please access http://localhost:8080/hello.

You should see the following.


I think it was very easy. Next time, we will use this environment to create routing.

Also, if you create an environment with Docker, the following article will be helpful. [Create a Go (Gin) environment with Docker]