访问路径是“http://127.0.0.1:8080/1/files/M03/C3/3D/oYYBAFbVNqGAF-KTAAAA9D1jMPQ965.p12”
在路由中的配置是
beego.Router("/1/files/*", &controllers.FileController{}, "post:Upload;delete:Delete")
在controller中想通过
url := fc.Ctx.Input.Param(":splat")
获取路由中“*”号的内容,但发现得到的url的变量值为:“1/files/M03/C3/3D/oYYBAFbVNqGAF-KTAAAA9D1jMPQ965.p12”
于是调试beego中的源码: `// Param returns router param by a given key.
func (input *BeegoInput) Param(key string) string {
for i, v := range input.pnames {
fmt.Println("get bee go param key:"+v )
fmt.Println("get bee go param val:"+input.pvalues[i] )
}
for i, v := range input.pnames {
if v == key && i <= len(input.pvalues) {
return input.pvalues[i]
}
}
return ""
}`
发现输出结果为: get bee go param key::splat get bee go param val:1/files/M03/C3/3D/oYYBAFbVNqGAF-KTAAAA9D1jMPQ965.p12 get bee go param key::splat get bee go param val:M03/C3/3D/oYYBAFbVNqGAF-KTAAAA9D1jMPQ965.p12 get bee go param key:0 get bee go param val:1 get bee go param key:1 get bee go param val:files get bee go param key:2 get bee go param val:M03 get bee go param key:3 get bee go param val:C3 get bee go param key:4 get bee go param val:3D get bee go param key:5 get bee go param val:oYYBAFbVNqGAF-KTAAAA9D1jMPQ965.p12
从测试结果可知, 有两个 ":splat"的key,只返回了第一个错误的结果,正确的应该是第二个":splat"的值。