Gin Starter

Quick start demo

Create main.go file

The exposing http port is provide by the `port` env, please bind the port read by the env.
main.go
package main

import (
    "github.com/gin-gonic/gin"
    "os"
)

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "pong",
        })
    })
    // read the `port` env
    port := os.Getenv("PORT")
    if port == "" {
        port = "8080"
    }
    r.Run(":" + port)
}

Init go.mod for project dependency

go mod init gin-demo
go mod tidy

Deploy to let.sh

if you haven't install lets, please take a look at the documentation: Cli Overview.

lets deploy
Edit this page on GitHub Updated at Tue, Jun 1, 2021