diff --git a/conf/settings.go b/conf/settings.go index 2b2d27c..a37c35d 100644 --- a/conf/settings.go +++ b/conf/settings.go @@ -46,8 +46,10 @@ rabbitmq_host = ${RABBITMQ_HOST} rabbitmq_user = ${RABBITMQ_USER} rabbitmq_password = ${RABBITMQ_PASSWORD} - store_backend = ${STORE_BACKEND} + +api_gateway_file_path = ${API_GATEWAY_FILE_PATH} + ` var Settings config.Configer @@ -74,6 +76,8 @@ var apigwManagerMaintainers string var userTokenKeyName string var pluginApiDebugUsername string +var apiGatewayFilePath string + func IsDevMode() bool { return Settings.DefaultString("environment", "dev") == "dev" } @@ -123,6 +127,14 @@ func ApigwBackendHost() string { return apigwBackendHost } +func initApigwFilePath() { + apiGatewayFilePath = Settings.DefaultString("api_gateway_file_path", "./data") +} + +func ApigwFilePath() string { + return apiGatewayFilePath +} + func initRedisAddr() { redisAddr = fmt.Sprintf( "%v:%v", @@ -306,5 +318,5 @@ func init() { initUserTokenKeyName() initPluginApiDebugUsername() setupLog() - + initApigwFilePath() } diff --git a/runner/collectstatics.go b/runner/collectstatics.go index ff7b477..db6b5e8 100644 --- a/runner/collectstatics.go +++ b/runner/collectstatics.go @@ -1,41 +1,90 @@ package runner import ( - "log" - "os/exec" - - "github.com/TencentBlueKing/beego-runtime/utils" + "embed" + "github.com/TencentBlueKing/beego-runtime/conf" + "io/fs" + "os" + "path/filepath" ) -func runCollectstatics() { - staticDir, err := utils.GetStaticDirPath() - if err != nil { - log.Fatalf("get static files dir failed: %v\n", err) +//go:embed views +var views embed.FS + +//go:embed static +var static embed.FS + +//go:embed data +var apiGwData embed.FS + +func copyFiles(sourceDir, targetDir string, dirEntries []fs.DirEntry, Fs embed.FS) { + for _, entry := range dirEntries { + sourcePath := filepath.Join(sourceDir, entry.Name()) + targetPath := filepath.Join(targetDir, entry.Name()) + + if entry.IsDir() { + // 如果是文件夹,则递归拷贝文件夹中的内容 + subDirEntries, err := Fs.ReadDir(sourcePath) + if err != nil { + panic(err) + } + err = os.MkdirAll(targetPath, 0755) + if err != nil { + panic(err) + } + copyFiles(sourcePath, targetPath, subDirEntries, Fs) + } else { + // 如果是文件,则拷贝文件内容 + fileData, err := Fs.ReadFile(sourcePath) + if err != nil { + panic(err) + } + err = os.WriteFile(targetPath, fileData, 0644) + if err != nil { + panic(err) + } + } } - viewPath, err := utils.GetViewPath() +} + +func syncFile() { + ViewDirEntries, err := views.ReadDir("views") if err != nil { - log.Fatalf("get view path failed: %v\n", err) + panic(err) } - definitionPath, err := utils.GetApigwDefinitionPath() + StaticDirEntries, err := static.ReadDir("static") if err != nil { - log.Fatalf("get apigw definition path failed: %v\n", err) + panic(err) } - resourcesPath, err := utils.GetApigwResourcesPath() + + err = os.MkdirAll("./views", 0755) if err != nil { - log.Fatalf("get apigw resources path failed: %v\n", err) + panic(err) } - cmds := []*exec.Cmd{ - exec.Command("cp", "-r", staticDir, "."), - exec.Command("cp", "-r", viewPath, "."), - exec.Command("cp", "-r", definitionPath, "."), - exec.Command("cp", "-r", resourcesPath, "."), + err = os.MkdirAll("./static", 0755) + if err != nil { + panic(err) } - for _, c := range cmds { - log.Printf("run collect static command: %v\n", c) - if err := c.Run(); err != nil { - log.Fatalf("collect static failed: %v\n", err) + copyFiles("views", "./views", ViewDirEntries, views) + copyFiles("static", "./static", StaticDirEntries, static) + + if !conf.IsDevMode() { + + err = os.MkdirAll("./data", 0755) + if err != nil { + panic(err) } + + ApiGwDirEntries, err := apiGwData.ReadDir("data") + if err != nil { + panic(err) + } + copyFiles("data", "./data", ApiGwDirEntries, apiGwData) } } + +func runCollectstatics() { + syncFile() +} diff --git a/data/api-definition.yml b/runner/data/api-definition.yml similarity index 100% rename from data/api-definition.yml rename to runner/data/api-definition.yml diff --git a/data/api-resources.yml b/runner/data/api-resources.yml similarity index 100% rename from data/api-resources.yml rename to runner/data/api-resources.yml diff --git a/runner/server.go b/runner/server.go index 82b5e90..6a71577 100644 --- a/runner/server.go +++ b/runner/server.go @@ -6,32 +6,15 @@ import ( "github.com/TencentBlueKing/beego-runtime/conf" "github.com/TencentBlueKing/beego-runtime/routers" - runtimeUtils "github.com/TencentBlueKing/beego-runtime/utils" "github.com/beego/beego/v2/server/web" ) func runServer() { var staticDir string var viewPath string - var err error - if conf.IsDevMode() { - staticDir, err = runtimeUtils.GetStaticDirPath() - if err != nil { - log.Fatalf("get static files dir failed: %v\n", err) - } - } else { - staticDir = "static" - } + staticDir = "static" log.Printf("serve /static at %v\n", staticDir) - - if conf.IsDevMode() { - viewPath, err = runtimeUtils.GetViewPath() - if err != nil { - log.Fatalf("get view path failed: %v\n", err) - } - } else { - viewPath = "views" - } + viewPath = "views" log.Printf("serve views at %v\n", viewPath) web.BConfig.CopyRequestBody = true diff --git a/static/assets/css/5.f3a15fb.css b/runner/static/assets/css/5.f3a15fb.css similarity index 100% rename from static/assets/css/5.f3a15fb.css rename to runner/static/assets/css/5.f3a15fb.css diff --git a/static/assets/css/6.4d4331a.css b/runner/static/assets/css/6.4d4331a.css similarity index 100% rename from static/assets/css/6.4d4331a.css rename to runner/static/assets/css/6.4d4331a.css diff --git a/static/assets/css/app.8df5bf2.css b/runner/static/assets/css/app.8df5bf2.css similarity index 100% rename from static/assets/css/app.8df5bf2.css rename to runner/static/assets/css/app.8df5bf2.css diff --git a/static/assets/fonts/codicon.a609dc0.ttf b/runner/static/assets/fonts/codicon.a609dc0.ttf similarity index 100% rename from static/assets/fonts/codicon.a609dc0.ttf rename to runner/static/assets/fonts/codicon.a609dc0.ttf diff --git a/static/assets/fonts/element-icons.535877f.woff b/runner/static/assets/fonts/element-icons.535877f.woff similarity index 100% rename from static/assets/fonts/element-icons.535877f.woff rename to runner/static/assets/fonts/element-icons.535877f.woff diff --git a/static/assets/fonts/element-icons.732389d.ttf b/runner/static/assets/fonts/element-icons.732389d.ttf similarity index 100% rename from static/assets/fonts/element-icons.732389d.ttf rename to runner/static/assets/fonts/element-icons.732389d.ttf diff --git a/static/assets/fonts/iconcool.73b7ae4.woff b/runner/static/assets/fonts/iconcool.73b7ae4.woff similarity index 100% rename from static/assets/fonts/iconcool.73b7ae4.woff rename to runner/static/assets/fonts/iconcool.73b7ae4.woff diff --git a/static/assets/fonts/iconcool.92e669c.eot b/runner/static/assets/fonts/iconcool.92e669c.eot similarity index 100% rename from static/assets/fonts/iconcool.92e669c.eot rename to runner/static/assets/fonts/iconcool.92e669c.eot diff --git a/static/assets/fonts/iconcool.99a84d9.ttf b/runner/static/assets/fonts/iconcool.99a84d9.ttf similarity index 100% rename from static/assets/fonts/iconcool.99a84d9.ttf rename to runner/static/assets/fonts/iconcool.99a84d9.ttf diff --git a/static/assets/img/iconcool.3a0bc10.svg b/runner/static/assets/img/iconcool.3a0bc10.svg similarity index 100% rename from static/assets/img/iconcool.3a0bc10.svg rename to runner/static/assets/img/iconcool.3a0bc10.svg diff --git a/static/assets/index.html b/runner/static/assets/index.html similarity index 100% rename from static/assets/index.html rename to runner/static/assets/index.html diff --git a/static/assets/js/0.c1242de.js b/runner/static/assets/js/0.c1242de.js similarity index 100% rename from static/assets/js/0.c1242de.js rename to runner/static/assets/js/0.c1242de.js diff --git a/static/assets/js/10.114016f.js b/runner/static/assets/js/10.114016f.js similarity index 100% rename from static/assets/js/10.114016f.js rename to runner/static/assets/js/10.114016f.js diff --git a/static/assets/js/11.11ae4f7.js b/runner/static/assets/js/11.11ae4f7.js similarity index 100% rename from static/assets/js/11.11ae4f7.js rename to runner/static/assets/js/11.11ae4f7.js diff --git a/static/assets/js/12.3c7b173.js b/runner/static/assets/js/12.3c7b173.js similarity index 100% rename from static/assets/js/12.3c7b173.js rename to runner/static/assets/js/12.3c7b173.js diff --git a/static/assets/js/13.b6a58d0.js b/runner/static/assets/js/13.b6a58d0.js similarity index 100% rename from static/assets/js/13.b6a58d0.js rename to runner/static/assets/js/13.b6a58d0.js diff --git a/static/assets/js/14.db809a8.js b/runner/static/assets/js/14.db809a8.js similarity index 100% rename from static/assets/js/14.db809a8.js rename to runner/static/assets/js/14.db809a8.js diff --git a/static/assets/js/15.42c10e7.js b/runner/static/assets/js/15.42c10e7.js similarity index 100% rename from static/assets/js/15.42c10e7.js rename to runner/static/assets/js/15.42c10e7.js diff --git a/static/assets/js/16.0792da5.js b/runner/static/assets/js/16.0792da5.js similarity index 100% rename from static/assets/js/16.0792da5.js rename to runner/static/assets/js/16.0792da5.js diff --git a/static/assets/js/17.7c96e4d.js b/runner/static/assets/js/17.7c96e4d.js similarity index 100% rename from static/assets/js/17.7c96e4d.js rename to runner/static/assets/js/17.7c96e4d.js diff --git a/static/assets/js/18.99a180b.js b/runner/static/assets/js/18.99a180b.js similarity index 100% rename from static/assets/js/18.99a180b.js rename to runner/static/assets/js/18.99a180b.js diff --git a/static/assets/js/19.566392e.js b/runner/static/assets/js/19.566392e.js similarity index 100% rename from static/assets/js/19.566392e.js rename to runner/static/assets/js/19.566392e.js diff --git a/static/assets/js/20.14c582e.js b/runner/static/assets/js/20.14c582e.js similarity index 100% rename from static/assets/js/20.14c582e.js rename to runner/static/assets/js/20.14c582e.js diff --git a/static/assets/js/21.fd978d6.js b/runner/static/assets/js/21.fd978d6.js similarity index 100% rename from static/assets/js/21.fd978d6.js rename to runner/static/assets/js/21.fd978d6.js diff --git a/static/assets/js/22.c6f2aea.js b/runner/static/assets/js/22.c6f2aea.js similarity index 100% rename from static/assets/js/22.c6f2aea.js rename to runner/static/assets/js/22.c6f2aea.js diff --git a/static/assets/js/23.d3397e7.js b/runner/static/assets/js/23.d3397e7.js similarity index 100% rename from static/assets/js/23.d3397e7.js rename to runner/static/assets/js/23.d3397e7.js diff --git a/static/assets/js/24.e1baa3f.js b/runner/static/assets/js/24.e1baa3f.js similarity index 100% rename from static/assets/js/24.e1baa3f.js rename to runner/static/assets/js/24.e1baa3f.js diff --git a/static/assets/js/25.def2ddc.js b/runner/static/assets/js/25.def2ddc.js similarity index 100% rename from static/assets/js/25.def2ddc.js rename to runner/static/assets/js/25.def2ddc.js diff --git a/static/assets/js/26.8e778dc.js b/runner/static/assets/js/26.8e778dc.js similarity index 100% rename from static/assets/js/26.8e778dc.js rename to runner/static/assets/js/26.8e778dc.js diff --git a/static/assets/js/27.6844850.js b/runner/static/assets/js/27.6844850.js similarity index 100% rename from static/assets/js/27.6844850.js rename to runner/static/assets/js/27.6844850.js diff --git a/static/assets/js/28.2bb05b3.js b/runner/static/assets/js/28.2bb05b3.js similarity index 100% rename from static/assets/js/28.2bb05b3.js rename to runner/static/assets/js/28.2bb05b3.js diff --git a/static/assets/js/29.c4b6dea.js b/runner/static/assets/js/29.c4b6dea.js similarity index 100% rename from static/assets/js/29.c4b6dea.js rename to runner/static/assets/js/29.c4b6dea.js diff --git a/static/assets/js/30.d404e53.js b/runner/static/assets/js/30.d404e53.js similarity index 100% rename from static/assets/js/30.d404e53.js rename to runner/static/assets/js/30.d404e53.js diff --git a/static/assets/js/31.fd04709.js b/runner/static/assets/js/31.fd04709.js similarity index 100% rename from static/assets/js/31.fd04709.js rename to runner/static/assets/js/31.fd04709.js diff --git a/static/assets/js/32.d09007f.js b/runner/static/assets/js/32.d09007f.js similarity index 100% rename from static/assets/js/32.d09007f.js rename to runner/static/assets/js/32.d09007f.js diff --git a/static/assets/js/33.f4ee229.js b/runner/static/assets/js/33.f4ee229.js similarity index 100% rename from static/assets/js/33.f4ee229.js rename to runner/static/assets/js/33.f4ee229.js diff --git a/static/assets/js/34.aadf28f.js b/runner/static/assets/js/34.aadf28f.js similarity index 100% rename from static/assets/js/34.aadf28f.js rename to runner/static/assets/js/34.aadf28f.js diff --git a/static/assets/js/35.2886542.js b/runner/static/assets/js/35.2886542.js similarity index 100% rename from static/assets/js/35.2886542.js rename to runner/static/assets/js/35.2886542.js diff --git a/static/assets/js/36.f111012.js b/runner/static/assets/js/36.f111012.js similarity index 100% rename from static/assets/js/36.f111012.js rename to runner/static/assets/js/36.f111012.js diff --git a/static/assets/js/37.af9b862.js b/runner/static/assets/js/37.af9b862.js similarity index 100% rename from static/assets/js/37.af9b862.js rename to runner/static/assets/js/37.af9b862.js diff --git a/static/assets/js/38.711e3e8.js b/runner/static/assets/js/38.711e3e8.js similarity index 100% rename from static/assets/js/38.711e3e8.js rename to runner/static/assets/js/38.711e3e8.js diff --git a/static/assets/js/39.bf1bfa2.js b/runner/static/assets/js/39.bf1bfa2.js similarity index 100% rename from static/assets/js/39.bf1bfa2.js rename to runner/static/assets/js/39.bf1bfa2.js diff --git a/static/assets/js/4.4b17f60.js b/runner/static/assets/js/4.4b17f60.js similarity index 100% rename from static/assets/js/4.4b17f60.js rename to runner/static/assets/js/4.4b17f60.js diff --git a/static/assets/js/40.888c480.js b/runner/static/assets/js/40.888c480.js similarity index 100% rename from static/assets/js/40.888c480.js rename to runner/static/assets/js/40.888c480.js diff --git a/static/assets/js/41.79ca8bd.js b/runner/static/assets/js/41.79ca8bd.js similarity index 100% rename from static/assets/js/41.79ca8bd.js rename to runner/static/assets/js/41.79ca8bd.js diff --git a/static/assets/js/42.a07bd42.js b/runner/static/assets/js/42.a07bd42.js similarity index 100% rename from static/assets/js/42.a07bd42.js rename to runner/static/assets/js/42.a07bd42.js diff --git a/static/assets/js/43.abf0645.js b/runner/static/assets/js/43.abf0645.js similarity index 100% rename from static/assets/js/43.abf0645.js rename to runner/static/assets/js/43.abf0645.js diff --git a/static/assets/js/44.a877334.js b/runner/static/assets/js/44.a877334.js similarity index 100% rename from static/assets/js/44.a877334.js rename to runner/static/assets/js/44.a877334.js diff --git a/static/assets/js/45.8c98a46.js b/runner/static/assets/js/45.8c98a46.js similarity index 100% rename from static/assets/js/45.8c98a46.js rename to runner/static/assets/js/45.8c98a46.js diff --git a/static/assets/js/46.6d36eaf.js b/runner/static/assets/js/46.6d36eaf.js similarity index 100% rename from static/assets/js/46.6d36eaf.js rename to runner/static/assets/js/46.6d36eaf.js diff --git a/static/assets/js/47.ace99bb.js b/runner/static/assets/js/47.ace99bb.js similarity index 100% rename from static/assets/js/47.ace99bb.js rename to runner/static/assets/js/47.ace99bb.js diff --git a/static/assets/js/48.ee9a3a4.js b/runner/static/assets/js/48.ee9a3a4.js similarity index 100% rename from static/assets/js/48.ee9a3a4.js rename to runner/static/assets/js/48.ee9a3a4.js diff --git a/static/assets/js/49.f76e1c2.js b/runner/static/assets/js/49.f76e1c2.js similarity index 100% rename from static/assets/js/49.f76e1c2.js rename to runner/static/assets/js/49.f76e1c2.js diff --git a/static/assets/js/5.5cf6d93.js b/runner/static/assets/js/5.5cf6d93.js similarity index 100% rename from static/assets/js/5.5cf6d93.js rename to runner/static/assets/js/5.5cf6d93.js diff --git a/static/assets/js/50.9d1d031.js b/runner/static/assets/js/50.9d1d031.js similarity index 100% rename from static/assets/js/50.9d1d031.js rename to runner/static/assets/js/50.9d1d031.js diff --git a/static/assets/js/51.842db90.js b/runner/static/assets/js/51.842db90.js similarity index 100% rename from static/assets/js/51.842db90.js rename to runner/static/assets/js/51.842db90.js diff --git a/static/assets/js/52.566f5f5.js b/runner/static/assets/js/52.566f5f5.js similarity index 100% rename from static/assets/js/52.566f5f5.js rename to runner/static/assets/js/52.566f5f5.js diff --git a/static/assets/js/53.01c2a6d.js b/runner/static/assets/js/53.01c2a6d.js similarity index 100% rename from static/assets/js/53.01c2a6d.js rename to runner/static/assets/js/53.01c2a6d.js diff --git a/static/assets/js/54.e74e2b2.js b/runner/static/assets/js/54.e74e2b2.js similarity index 100% rename from static/assets/js/54.e74e2b2.js rename to runner/static/assets/js/54.e74e2b2.js diff --git a/static/assets/js/55.60ac924.js b/runner/static/assets/js/55.60ac924.js similarity index 100% rename from static/assets/js/55.60ac924.js rename to runner/static/assets/js/55.60ac924.js diff --git a/static/assets/js/56.3df2099.js b/runner/static/assets/js/56.3df2099.js similarity index 100% rename from static/assets/js/56.3df2099.js rename to runner/static/assets/js/56.3df2099.js diff --git a/static/assets/js/57.8508043.js b/runner/static/assets/js/57.8508043.js similarity index 100% rename from static/assets/js/57.8508043.js rename to runner/static/assets/js/57.8508043.js diff --git a/static/assets/js/58.53bb637.js b/runner/static/assets/js/58.53bb637.js similarity index 100% rename from static/assets/js/58.53bb637.js rename to runner/static/assets/js/58.53bb637.js diff --git a/static/assets/js/59.3742e3e.js b/runner/static/assets/js/59.3742e3e.js similarity index 100% rename from static/assets/js/59.3742e3e.js rename to runner/static/assets/js/59.3742e3e.js diff --git a/static/assets/js/6.9824b38.js b/runner/static/assets/js/6.9824b38.js similarity index 100% rename from static/assets/js/6.9824b38.js rename to runner/static/assets/js/6.9824b38.js diff --git a/static/assets/js/60.ddd7ed7.js b/runner/static/assets/js/60.ddd7ed7.js similarity index 100% rename from static/assets/js/60.ddd7ed7.js rename to runner/static/assets/js/60.ddd7ed7.js diff --git a/static/assets/js/61.b95ae34.js b/runner/static/assets/js/61.b95ae34.js similarity index 100% rename from static/assets/js/61.b95ae34.js rename to runner/static/assets/js/61.b95ae34.js diff --git a/static/assets/js/62.5eac4ec.js b/runner/static/assets/js/62.5eac4ec.js similarity index 100% rename from static/assets/js/62.5eac4ec.js rename to runner/static/assets/js/62.5eac4ec.js diff --git a/static/assets/js/63.f1d8eec.js b/runner/static/assets/js/63.f1d8eec.js similarity index 100% rename from static/assets/js/63.f1d8eec.js rename to runner/static/assets/js/63.f1d8eec.js diff --git a/static/assets/js/64.7d4a99a.js b/runner/static/assets/js/64.7d4a99a.js similarity index 100% rename from static/assets/js/64.7d4a99a.js rename to runner/static/assets/js/64.7d4a99a.js diff --git a/static/assets/js/65.1fea06b.js b/runner/static/assets/js/65.1fea06b.js similarity index 100% rename from static/assets/js/65.1fea06b.js rename to runner/static/assets/js/65.1fea06b.js diff --git a/static/assets/js/66.34485bf.js b/runner/static/assets/js/66.34485bf.js similarity index 100% rename from static/assets/js/66.34485bf.js rename to runner/static/assets/js/66.34485bf.js diff --git a/static/assets/js/67.fc5a3f9.js b/runner/static/assets/js/67.fc5a3f9.js similarity index 100% rename from static/assets/js/67.fc5a3f9.js rename to runner/static/assets/js/67.fc5a3f9.js diff --git a/static/assets/js/68.d390bc6.js b/runner/static/assets/js/68.d390bc6.js similarity index 100% rename from static/assets/js/68.d390bc6.js rename to runner/static/assets/js/68.d390bc6.js diff --git a/static/assets/js/69.74d0d7d.js b/runner/static/assets/js/69.74d0d7d.js similarity index 100% rename from static/assets/js/69.74d0d7d.js rename to runner/static/assets/js/69.74d0d7d.js diff --git a/static/assets/js/7.80ce862.js b/runner/static/assets/js/7.80ce862.js similarity index 100% rename from static/assets/js/7.80ce862.js rename to runner/static/assets/js/7.80ce862.js diff --git a/static/assets/js/8.6eeb23d.js b/runner/static/assets/js/8.6eeb23d.js similarity index 100% rename from static/assets/js/8.6eeb23d.js rename to runner/static/assets/js/8.6eeb23d.js diff --git a/static/assets/js/9.19d508c.js b/runner/static/assets/js/9.19d508c.js similarity index 100% rename from static/assets/js/9.19d508c.js rename to runner/static/assets/js/9.19d508c.js diff --git a/static/assets/js/app.f68f97c.js b/runner/static/assets/js/app.f68f97c.js similarity index 100% rename from static/assets/js/app.f68f97c.js rename to runner/static/assets/js/app.f68f97c.js diff --git a/static/assets/js/runtime.432ba22.js b/runner/static/assets/js/runtime.432ba22.js similarity index 100% rename from static/assets/js/runtime.432ba22.js rename to runner/static/assets/js/runtime.432ba22.js diff --git a/static/assets/js/vue-lib.4ec3d28.js b/runner/static/assets/js/vue-lib.4ec3d28.js similarity index 100% rename from static/assets/js/vue-lib.4ec3d28.js rename to runner/static/assets/js/vue-lib.4ec3d28.js diff --git a/static/editor.worker.js b/runner/static/editor.worker.js similarity index 100% rename from static/editor.worker.js rename to runner/static/editor.worker.js diff --git a/static/images/favicon.png b/runner/static/images/favicon.png similarity index 100% rename from static/images/favicon.png rename to runner/static/images/favicon.png diff --git a/static/json.worker.js b/runner/static/json.worker.js similarity index 100% rename from static/json.worker.js rename to runner/static/json.worker.js diff --git a/runner/syncapigw.go b/runner/syncapigw.go index f22d57f..1c7a991 100644 --- a/runner/syncapigw.go +++ b/runner/syncapigw.go @@ -6,7 +6,6 @@ import ( "time" "github.com/TencentBlueKing/beego-runtime/conf" - "github.com/TencentBlueKing/beego-runtime/utils" "github.com/TencentBlueKing/bk-apigateway-sdks/core/bkapi" "github.com/TencentBlueKing/bk-apigateway-sdks/manager" "github.com/sirupsen/logrus" @@ -15,14 +14,11 @@ import ( func runSyncApigw() { logger := logrus.New() // load data path - definitionPath, err := utils.GetApigwDefinitionPath() - if err != nil { - log.Fatalf("get apigw definition path error: %v\n", err) - } - resourcesPath, err := utils.GetApigwResourcesPath() - if err != nil { - log.Fatalf("get apigw resources path error: %v\n", err) - } + + apiGwFilePath := conf.ApigwFilePath() + + definitionPath := fmt.Sprintf("%s/%s", apiGwFilePath, "api-definition.yml") + resourcesPath := fmt.Sprintf("%s/%s", apiGwFilePath, "api-resources.yml") // create manager config := bkapi.ClientConfig{ diff --git a/views/debug_panel.tpl b/runner/views/debug_panel.tpl similarity index 100% rename from views/debug_panel.tpl rename to runner/views/debug_panel.tpl diff --git a/utils/module.go b/utils/module.go index 271bfd7..d4b585b 100644 --- a/utils/module.go +++ b/utils/module.go @@ -1,67 +1 @@ package utils - -import ( - "os" - "path" - - "github.com/TencentBlueKing/beego-runtime/info" - "golang.org/x/mod/module" -) - -func GetApigwDefinitionPath() (string, error) { - baseDir, err := GetModulePath("github.com/TencentBlueKing/beego-runtime", info.Version()) - if err != nil { - return "", err - } - - return path.Join(baseDir, "data/api-definition.yml"), nil -} - -func GetApigwResourcesPath() (string, error) { - baseDir, err := GetModulePath("github.com/TencentBlueKing/beego-runtime", info.Version()) - if err != nil { - return "", err - } - - return path.Join(baseDir, "data/api-resources.yml"), nil -} - -func GetStaticDirPath() (string, error) { - baseDir, err := GetModulePath("github.com/TencentBlueKing/beego-runtime", info.Version()) - if err != nil { - return "", err - } - - return path.Join(baseDir, "static"), nil -} - -func GetViewPath() (string, error) { - baseDir, err := GetModulePath("github.com/TencentBlueKing/beego-runtime", info.Version()) - if err != nil { - return "", err - } - - return path.Join(baseDir, "views"), nil -} - -func GetModulePath(name, version string) (string, error) { - // first we need GOMODCACHE - cache, ok := os.LookupEnv("GOMODCACHE") - if !ok { - cache = path.Join(os.Getenv("GOPATH"), "pkg", "mod") - } - - // then we need to escape path - escapedPath, err := module.EscapePath(name) - if err != nil { - return "", err - } - - // version also - escapedVersion, err := module.EscapeVersion(version) - if err != nil { - return "", err - } - - return path.Join(cache, escapedPath+"@"+escapedVersion), nil -}