Golang Gin框架:如何获取HTTP请求方法名
在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/fB49 著作权归作者所有。请勿转载和采集!