1. 先上代码: ```go package main

    import ( “github.com/gin-gonic/gin” “net/http” )

    func main() { // Creates a gin router with default middleware: // logger and recovery (crash-free) middleware router := gin.Default()

    1. router.GET("/someGet", getting)
    2. router.POST("/somePost", posting)
    3. router.PUT("/somePut", putting)
    4. router.DELETE("/someDelete", deleting)
    5. // By default it serves on :8080 unless a
    6. // PORT environment variable was defined.
    7. router.Run()
    8. // router.Run(":3000") for a hard coded port

    }

    func getting(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ “code”: “GET”, }) }

    func posting(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ “code”: “POST”, }) }

    func putting(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ “code”: “PUT”, }) }

    func deleting(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ “code”: “DELETE”, }) } ```

    1. 效果:(使用 软件 postman)

    image.png