Gin是用Golang实现的一种Web框架。基于 httprouter,它提供了类似martini但更好性能(路由性能约快40倍)的API服务. 如果你希望构建一个高性能的生产环境,你会喜欢上使用 Gin。
Gin github地址:https://github.com/gin-gonic/gin
于是简单的学习了下:
打开main.go
package main import ( "github.com/gin-gonic/gin" "net/http" ) func main() { router := gin.Default() // This handler will match /user/john but will not match neither /user/ or /user router.GET("/user/:name", func(c *gin.Context) { name := c.Param("name") c.String(http.StatusOK, "Hello %s", name) }) // However, this one will match /user/john/ and also /user/john/send // If no other routers match /user/john, it will redirect to /user/john/ router.POST("/user/:name/*action", func(c *gin.Context) { name := c.Param("name") action := c.Param("action") message := name + " is " + action c.String(http.StatusOK, message) }) //router.Run(":8080") http.ListenAndServe(":8080", router) }
浏览器访问:http://localhost:8080/user/webyang.net,即可看到 Hello webyang.net。
简易项目,持续更新。。。。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/98489.html