golang 如何从ginContext中获取方法名
在Gin框架中,可以通过c.Request.Method来获取HTTP请求的方法名。
示例代码如下:
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/hello", func(c *gin.Context) {
method := c.Request.Method
c.String(200, "Hello, method: "+method)
})
r.Run(":8080")
}
在上述示例中,使用c.Request.Method获取HTTP请求的方法名,并将其返回给客户端。
原文地址: https://www.cveoy.top/t/topic/hUNd 著作权归作者所有。请勿转载和采集!