Gin安装
Download and install it:
$ go get gopkg.in/gin-gonic/gin.v1
Import it in your code:
import “gopkg.in/gin-gonic/gin.v1”
(Optional) Import net/http. This is required for example if using constants such as http.StatusOK.
import “net/http”
API Examples
Using GET, POST, PUT, PATCH, DELETE and OPTIONS
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)
router.PATCH("/somePatch", patching)
router.HEAD("/someHead", head)
router.OPTIONS("/someOptions", options)
// By default it serves on :8080 unless a
// PORT environment variable was defined.
router.Run()
// router.Run(":3000") for a hard coded port
}