- 先上代码: ```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()
router.GET("/someGet", getting)router.POST("/somePost", posting)router.PUT("/somePut", putting)router.DELETE("/someDelete", deleting)// By default it serves on :8080 unless a// PORT environment variable was defined.router.Run()// 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”, }) } ```
- 效果:(使用 软件
postman)

