diff --git a/gala-ops/server/httphandler/metricdata.go b/gala-ops/server/httphandler/metricdata.go index ec4c716890c887ecb95c5101f3c30fcc64115cac..bd5a427628a56cdbc561938d739f2a99335db967 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 9edd5c5d9ee00ba985ea2d212bcc481f1c43c32b..22f365b469680e4f1d8bf88242f20691ac13f973 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 0000000000000000000000000000000000000000..21eeefb62f1b6d557cad79f2752533120a1a1f9c --- /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) + } +}