Skip to content
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

Merged
merged 7 commits into from
Aug 1, 2017
Merged

Add some APIs #132

merged 7 commits into from
Aug 1, 2017

Conversation

junhuizx
Copy link
Contributor

@junhuizx junhuizx commented Jun 9, 2017

Add 4 APIs:

  1. update hostgroup's name:
    /api/v1/hostgroup/update/#{hostgroup_id}
  2. update team's name:
    /api/v1/user/u/:uid/teams
  3. get host groups by template:
    /api/v1/template/#{template_id}/hostgroup
  4. get use's teams:
    /api/v1/user/u/:uid/teams

@laiwei
Copy link
Member

laiwei commented Jun 15, 2017

@junhuizx fmt check没有通过,你得检查一下

我看是因为代码文件的保存格式有问题,你可能需要dos2uinx工具转换一下

@junhuizx
Copy link
Contributor Author

@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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里fmt check 没有通过

@laiwei
Copy link
Member

laiwei commented Jul 3, 2017

@junhuizx

你先对你的代码执行 go fmt,这样格式就ok了。

然后 make 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)
Copy link
Member

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:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边加update是因为和上面的put方法冲突, 这个问题有其他方法解决吗

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同名不影响,因为方法不同,看 Line 23, 24 就知道

Copy link
Contributor Author

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

Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junhuizx 这个冲突的问题,我确实也遇到过,不过我没有找到方法

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junhuizx 看一下 @masato25 的建议?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,我试一下

junhuizx and others added 6 commits July 13, 2017 14:21
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>
@masato25 masato25 merged commit b93c63e into open-falcon:master Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants