Gin Any方法路由

时间:2021-08-30 06:09:56   收藏:0   阅读:6
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)
	}
}


原文:https://www.cnblogs.com/liy36/p/15202318.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!