From 2d128b650340372d04d1ec375625766bb4cf7fc1 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Mon, 12 Jun 2023 16:22:37 +0800 Subject: [PATCH] move initrouter() in from main.go to router.go --- gala-ops/server/httphandler/metricdata.go | 6 +++++ gala-ops/server/main.go | 29 ++++------------------- gala-ops/server/router/router.go | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 gala-ops/server/router/router.go diff --git a/gala-ops/server/httphandler/metricdata.go b/gala-ops/server/httphandler/metricdata.go index ec4c7168..bd5a4276 100644 --- a/gala-ops/server/httphandler/metricdata.go +++ b/gala-ops/server/httphandler/metricdata.go @@ -24,3 +24,9 @@ func TargetsList(ctx *gin.Context) { } ctx.JSON(http.StatusOK, data) } + + + + + + diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go index 9edd5c5d..22f365b4 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -13,6 +13,7 @@ import ( "openeuler.org/PilotGo/gala-ops-plugin/config" "openeuler.org/PilotGo/gala-ops-plugin/database" "openeuler.org/PilotGo/gala-ops-plugin/httphandler" + "openeuler.org/PilotGo/gala-ops-plugin/router" ) const Version = "0.0.1" @@ -37,7 +38,7 @@ func main() { InitLogger() - router := gin.Default() + engine := gin.Default() PluginClient := client.DefaultClient(PluginInfo) // 临时给server赋值 @@ -59,9 +60,9 @@ func main() { PromePlugin: promeplugin, } - httphandler.Galaops.Sdkmethod.RegisterHandlers(router) - InitRouter(router) - if err := router.Run(config.Config().Http.Addr); err != nil { + httphandler.Galaops.Sdkmethod.RegisterHandlers(engine) + router.InitRouter(engine) + if err := engine.Run(config.Config().Http.Addr); err != nil { logger.Fatal("failed to run server") } } @@ -73,26 +74,6 @@ func InitLogger() { } } -func InitRouter(router *gin.Engine) { - api := router.Group("/plugin/gala-ops/api") - { - // 脚本执行结果接口 - // api.PUT("/run_script_result", httphandler.RunScriptResult) - - // 安装/升级/卸载gala-gopher监控终端 - api.PUT("/install_gopher", httphandler.InstallGopher) - api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) - api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) - } - - metrics := router.Group("plugin/gala-ops/api/metrics") - { - metrics.GET("/targets_list", func(ctx *gin.Context) { - httphandler.TargetsList(ctx) - }) - } -} - func getpromeplugininfo(pilotgoserver string) (map[string]interface{}, error) { resp, err := http.Get(pilotgoserver + "/api/v1/plugins") if err != nil { diff --git a/gala-ops/server/router/router.go b/gala-ops/server/router/router.go new file mode 100644 index 00000000..21eeefb6 --- /dev/null +++ b/gala-ops/server/router/router.go @@ -0,0 +1,24 @@ +package router + +import ( + "github.com/gin-gonic/gin" + "openeuler.org/PilotGo/gala-ops-plugin/httphandler" +) + +func InitRouter(router *gin.Engine) { + api := router.Group("/plugin/gala-ops/api") + { + // 脚本执行结果接口 + // api.PUT("/run_script_result", httphandler.RunScriptResult) + + // 安装/升级/卸载gala-gopher监控终端 + api.PUT("/install_gopher", httphandler.InstallGopher) + api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) + api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) + } + + metrics := router.Group("plugin/gala-ops/api/metrics") + { + metrics.GET("/targets_list", httphandler.TargetsList) + } +} -- Gitee