Quickstart

    • Go 1.13 or above

    To install Gin package, you need to install Go and set your Go workspace first.

    1. Download and install it:
    1. Import it in your code:
    1. (Optional) Import net/http. This is required for example if using constants such as http.StatusOK.
    1. import "net/http"
    1. Copy a starting template inside your project
    1. $ curl https://raw.githubusercontent.com/gin-gonic/examples/master/basic/main.go > main.go
    1. Run your project
    1. $ go run main.go

    First, create a file called example.go:

    1. package main
    2. import "github.com/gin-gonic/gin"
    3. func main() {
    4. r.GET("/ping", func(c *gin.Context) {
    5. "message": "pong",
    6. })
    7. })
    8. r.Run() // listen and serve on 0.0.0.0:8080
    9. }

    And, You can run the code via go run example.go:

    1. # run example.go and visit 0.0.0.0:8080/ping on browser