Gin Any方法路由

package main

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

func main() {
	router := gin.Default()

	router.Any("/", func(ctx *gin.Context) {
		switch ctx.Request.Method {
		case http.MethodGet:
			ctx.JSON(http.StatusOK, gin.H{"Method": http.MethodGet})
		case http.MethodPost:
			ctx.JSON(http.StatusOK, gin.H{"Method": http.MethodPost})
		case http.MethodPut:
			ctx.JSON(http.StatusOK, gin.H{"Method": http.MethodPut})
		case http.MethodDelete:
			ctx.JSON(http.StatusOK, gin.H{"Method": http.MethodDelete})
		}
	})

	err := router.Run(":8080")
	if err != nil {
		panic(err)
	}
}


Gin Any方法路由

上一篇:CTO不写代码,凭什么拿高工资


下一篇:三层