Gin的路由类型:GET POST PUT DELETE
生活随笔
收集整理的這篇文章主要介紹了
Gin的路由类型:GET POST PUT DELETE
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
package mainimport ("fmt""net/http""github.com/gin-gonic/gin"
)func main() {r := gin.Default()// GET 獲取所有的文章信息r.GET("/posts", func(c *gin.Context) {c.String(http.StatusOK, "GET")})// POST 創(chuàng)建一篇新文章r.POST("/posts", func(c *gin.Context) {c.String(http.StatusOK, "POST")})// PUT 修改一篇文章r.PUT("/posts/:id", func(c *gin.Context) {c.String(http.StatusOK, fmt.Sprintf("PUT id: %s", c.Param("id")))})// DELETE 刪除一篇文件r.DELETE("/posts/", func(c *gin.Context) {c.String(http.StatusOK, "DELETE")})// 匹配所有請(qǐng)求方法/*MethodGet = "GET"MethodHead = "HEAD"MethodPost = "POST"MethodPut = "PUT"MethodPatch = "PATCH" // RFC 5789MethodDelete = "DELETE"MethodConnect = "CONNECT"MethodOptions = "OPTIONS"MethodTrace = "TRACE"*/r.Any("/users", func(c *gin.Context) {c.String(200, "any")})r.Run()
}
總結(jié)
以上是生活随笔為你收集整理的Gin的路由类型:GET POST PUT DELETE的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 解决关闭hdfs yarn spark
- 下一篇: Gin加载静态html img文件