当前位置:网站首页>go : gin路径参数
go : gin路径参数
2022-07-22 17:58:00 【IT工作者】
本文介绍 gin框架下如何获取路径参数
代码:
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
// This handler will match /user/john but will not match /user/ or /use
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.GET("/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")
}运行代码
客户端访问
->curl localhost:8080/user/world
Hello world->
->curl localhost:8080/user/world123
Hello world123->
->curl localhost:8080/user/world/123
world is /123->边栏推荐
猜你喜欢
随机推荐
Phoenix pit filling 5:column reference ambiguous or duplicate names columnName
Phoenix pit filling 3:the on duplicate key claim may not be used when a table has a global index
Ctfshow deserialization 255-263
Four traversal methods of map set
Ctfshow PHP feature
mysql5.7 多源复制
若依框架客户管理按照创建时间字段排序报错解决方法
MOVE PROTOCOL以跑步切入,构建运动大健康生态
regular expression
Life view
inception审核规则详解
通过DAO的现状,看Web3最具影响力的基础设施M-DAO
JQ realizes multiple switching effects without affecting each other
MySQL数据库记录总结
Media framework I of JMF introduction
备受关注的Bit.Store,最新动态一览
西班牙出差见闻之二(人情风俗)
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
[excel]如果去掉科学计数法,以及将正常的减号进行计算
MOVE PROTOCOL全球健康宣言,在运动中踏入Web3



![[excel]解决Excel和txt转换出现的“问题](/img/06/d81356d3128f52a4d43916e1938c13.png)





