Skip to content

Gin

Quick start demo

Create main.go file

WARNING

The exposing http port is provide by the port env, please bind the port read by the env.

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 download

Deploy to let.sh

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

lets deploy

Powered by let.sh