为了可读性,我将方法链拆分为多行:for _, e := range methods { switch e { case "GET": if len(name) > 0 { router.Handle(path, httpAjaxFunc(handler)) .Methods(e) .Headers("X-Requested-With", "XMLHttpRequest", "Payload", "") .Name(name[0]); } else { router.Handle(path, httpAjaxFunc(handler)) .Methods(e) .Headers("X-Requested-With", "XMLHttpRequest", "Payload", ""); }在第 29 行,文件控制器\路由\funcs.gosyntax 错误:意外。我怎样才能把它分成多行?
1 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
这有点丑陋,但我所知道的唯一方法:
for _, e := range methods {
switch e {
case "GET":
if len(name) > 0 {
router.Handle(path, httpAjaxFunc(handler)).
Methods(e).
Headers("X-Requested-With", "XMLHttpRequest", "Payload", "").
Name(name[0])
} else {
router.Handle(path, httpAjaxFunc(handler)).
Methods(e).
Headers("X-Requested-With", "XMLHttpRequest", "Payload", "")
}
- 1 回答
- 0 关注
- 193 浏览
添加回答
举报
0/150
提交
取消