-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some APIs #132
Add some APIs #132
Conversation
@junhuizx fmt check没有通过,你得检查一下 我看是因为代码文件的保存格式有问题,你可能需要dos2uinx工具转换一下 |
@laiwei 我在master上执行make fmt-check也是出错。 |
@@ -20,6 +20,7 @@ func Routes(r *gin.Engine) { | |||
tmpr.POST("", CreateTemplate) | |||
tmpr.GET("/:tpl_id", GetATemplate) | |||
tmpr.PUT("", UpdateTemplate) | |||
tmpr.GET("/:tpl_id/hostgroup", GetATemplateHostgroup) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里fmt check 没有通过
你先对你的代码执行 然后 |
@@ -23,6 +23,7 @@ func Routes(r *gin.Engine) { | |||
hostr.POST("/hostgroup/host", BindHostToHostGroup) | |||
hostr.PUT("/hostgroup/host", UnBindAHostToHostGroup) | |||
hostr.GET("/hostgroup/:host_group", GetHostGroup) | |||
hostr.PUT("/hostgroup/update/:host_group", PutHostGroup) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL里面不必有/update/部分,因为method为put就表明了要update:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边加update是因为和上面的put方法冲突, 这个问题有其他方法解决吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同名不影响,因为方法不同,看 Line 23, 24 就知道
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果把update去掉会和24行的put方法冲突,24行是:hostr.PUT("/hostgroup/host", UnBindAHostToHostGroup)
我查过,gin好像不支持正则之类的匹配,也调整过语句的顺序,但是还是会报错,难道不可以配成先匹配24行的,如果匹配不上就用26行的,gin可以配这样的逻辑吗?
错误日志如下:
panic: wildcard route ':host_group' conflicts with existing children in path '/api/v1/hostgroup/:host_group'
goroutine 21 [running]:
panic(0xa24f20, 0xc8202f9330)
/usr/lib/golang/src/runtime/panic.go:481 +0x3e6
github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin.(*node).insertChild(0xc820330cc0, 0xc82003fb01, 0xc82032d2d2, 0xb, 0xc82032d2c0, 0x1d, 0xc82032eb10, 0x5, 0x5)
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin/tree.go:275 +0x3b4
github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin.(*node).addRoute(0xc820330cc0, 0xc82032d2d2, 0xb, 0xc82032eb10, 0x5, 0x5)
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin/tree.go:231 +0xb81
github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin.(*Engine).addRoute(0xc8202fa0e0, 0xc114a0, 0x3, 0xc82032d2c0, 0x1d, 0xc82032eb10, 0x5, 0x5)
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin/gin.go:191 +0x258
github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin.(*RouterGroup).handle(0xc820297600, 0xc114a0, 0x3, 0xc83740, 0x16, 0xc82032eb10, 0x5, 0x5, 0x0, 0x0)
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin/routergroup.go:73 +0x110
github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin.(*RouterGroup).PUT(0xc820297600, 0xc83740, 0x16, 0xc82002f110, 0x1, 0x1, 0x0, 0x0)
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/vendor/github.com/gin-gonic/gin/routergroup.go:116 +0x81
github.com/open-falcon/falcon-plus/modules/api/app/controller/host.Routes(0xc8202fa0e0)
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/modules/api/app/controller/host/host_routes.go:26 +0x4a1
github.com/open-falcon/falcon-plus/modules/api/app/controller.StartGin(0xc8202ba6d0, 0xc, 0xc8202fa0e0)
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/modules/api/app/controller/routes.go:29 +0x187
created by main.main
/home/mywork/workspace/src/github.com/open-falcon/falcon-plus/modules/api/main.go:77 +0xad1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gin-gonic/gin#680
gin 是不支援regex matching的所以不建议这样使用. 会相冲的
你可以参照aggreator的put写法将id置入传入的post body之中
https://github.com/open-falcon/falcon-plus/blob/master/modules/api/app/controller/host/aggreator_controller.go#L133
建议routes可以使用 hostr.PUT("/hostgroup", PutHostGroup)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@junhuizx 这个冲突的问题,我确实也遇到过,不过我没有找到方法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK,我试一下
Signed-off-by: zjh <junhui.zhang@newtouch.cn>
Signed-off-by: zjh <junhui.zhang@newtouch.cn>
Signed-off-by: zjh <junhui.zhang@newtouch.cn>
Signed-off-by: zjh <junhui.zhang@newtouch.cn>
Signed-off-by: zjh <junhui.zhang@newtouch.cn>
Signed-off-by: junhui zhang <junhui.zhang@newtouhc.cn>
… in url Signed-off-by: zjh <junhui.zhang@newtouch.cn>
Add 4 APIs:
/api/v1/hostgroup/update/#{hostgroup_id}
/api/v1/user/u/:uid/teams
/api/v1/template/#{template_id}/hostgroup
/api/v1/user/u/:uid/teams