Route:
beego.ControllerComments{
Method: "Get",
Router: `/:userNAME`,
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(),
Filters: nil,
Params: nil}
日志:
aaa=> &{0xc000138fc0 <nil> [:username] [hjkhsbnmn123] map[RouterPattern:/v1/object/:userNAME] {{0 0} 0 0 0 0} [] <nil>}2019/12/03 14:24:28.292 [D] [server.go:2802] | 127.0.0.1| 200 | 951.8µs| match| GET /v1/object/hjkhsbnmn123 r:/v1/object/:userNAME
发现,参数竟然被转小写了...
1
nimeizhaopian 2019-12-03 16:55:53 +08:00
在 route 文件里有个 beego.AutoPrefix()函数,然后
func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface) { reflectVal := reflect.ValueOf(c) rt := reflectVal.Type() ct := reflect.Indirect(reflectVal).Type() controllerName := strings.TrimSuffix(ct.Name(), "Controller") for i := 0; i < rt.NumMethod(); i++ { if !utils.InSlice(rt.Method(i).Name, exceptMethod) { route := &ControllerInfo{} route.routerType = routerTypeBeego route.methods = map[string]string{"*": rt.Method(i).Name} route.controllerType = ct pattern := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(rt.Method(i).Name), "*") patternInit := path.Join(prefix, controllerName, rt.Method(i).Name, "*") patternFix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(rt.Method(i).Name)) patternFixInit := path.Join(prefix, controllerName, rt.Method(i).Name) route.pattern = pattern for m := range HTTPMETHOD { p.addToRouter(m, pattern, route) p.addToRouter(m, patternInit, route) p.addToRouter(m, patternFix, route) p.addToRouter(m, patternFixInit, route) } } } } patternFix := path.Join(prefix, strings.ToLower(controllerName), strings.ToLower(rt.Method(i).Name)) 这句话 |
2
slgz OP @nimeizhaopian #1 大佬牛批, 新手看半天没看懂
|
3
slgz OP @nimeizhaopian #1 感觉有点坑, beego 的文档没找到... 难道 go 圈的人, 都是看源码的吗
|
4
CEBBCAT 2019-12-09 00:58:37 +08:00 via Android
深夜跟楼主撩骚一下,想请问一下这个冬天收不收实习生?用 Go 接过一个客服系统,算法竞赛选手,拿过全国二等奖
|