[go language series] third party framework and Library — gin: a quick start

Time:2020-12-5

requirement
To install the gin package, you need to:
1. Install go (version 1.11 + required)
2. Set up go workspace

install
1. Download and install gin:

$ go get -u github.com/gin-gonic/gin

2. Introduce gin into the code:

import "github.com/gin-gonic/gin"

3. (optional) import net / HTTP. For example, if you use http.StatusOK For this type of constant, you need to do this:

import "net/http"

 

Quick start
1. Create a example.go And write the code:

package main

import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "pong",
        })
    })
    r. 0.0.0 for windows“ localhost:8080 ""
}

2. Running code

Enter the following command:

$ go run example.go

3. On the browser, access:

http://localhost:8080/ping

 

Recommended Today

Construction of Vue development environment and project creation under mac

start First of all, let’s take a look at the overall development environment of Vue. Homebrew: package manager under MAC system, similar to apt get under Linux, windows control panel – install and remove program Node.jsJavaScript runtime, which is similar to simultaneous interpretation in international conferences, can’t run various programming languages directly between different systems […]