From 62f71ad324136adb0aaf3f3cee18d53dcab827c4 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Fri, 13 Oct 2023 16:44:17 +0800 Subject: [PATCH] refactor: removed unused code (#6243) --- backend/server/api/api.go | 13 ++++--------- backend/server/main.go | 2 +- .../server/services/remote/plugin/plugin_impl.go | 2 +- backend/test/helper/client.go | 2 +- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/backend/server/api/api.go b/backend/server/api/api.go index 2faa423b655..698e9e1c9b3 100644 --- a/backend/server/api/api.go +++ b/backend/server/api/api.go @@ -56,7 +56,7 @@ Alternatively, you may downgrade back to the previous DevLake version. // @license.name Apache-2.0 // @host localhost:8080 // @BasePath / -func CreateApiService() { +func CreateApiService(router *gin.Engine) { // Get configuration v := config.GetConfig() // Initialize services @@ -64,18 +64,13 @@ func CreateApiService() { // Set gin mode gin.SetMode(v.GetString("MODE")) // Create a gin router - router := gin.Default() + if router == nil { + router = gin.Default() + } // For both protected and unprotected routes router.GET("/ping", ping.Get) router.GET("/version", version.Get) - router.GET("/userinfo", func(ctx *gin.Context) { - shared.ApiOutputSuccess(ctx, gin.H{ - "user": ctx.Request.Header.Get("X-Forwarded-User"), - "email": ctx.Request.Header.Get("X-Forwarded-Email"), - "logoutURI": config.GetConfig().GetString("LOGOUT_URI"), - }, http.StatusOK) - }) // Endpoint to proceed database migration router.GET("/proceed-db-migration", func(ctx *gin.Context) { diff --git a/backend/server/main.go b/backend/server/main.go index 5988dea91d6..514a179e614 100644 --- a/backend/server/main.go +++ b/backend/server/main.go @@ -30,5 +30,5 @@ func main() { if encryptionSecret == "" { panic("ENCRYPTION_SECRET must be set in environment variable or .env file") } - api.CreateApiService() + api.CreateApiService(nil) } diff --git a/backend/server/services/remote/plugin/plugin_impl.go b/backend/server/services/remote/plugin/plugin_impl.go index 7ced36f9dea..6242b160053 100644 --- a/backend/server/services/remote/plugin/plugin_impl.go +++ b/backend/server/services/remote/plugin/plugin_impl.go @@ -84,7 +84,7 @@ func newPlugin(info *models.PluginInfo, invoker bridge.Invoker) (*remotePluginIm } openApiSpec, err := doc.GenerateOpenApiSpec(info) if err != nil { - return nil, errors.Default.Wrap(err, fmt.Sprintf("Couldn't generate OpenAPI spec for plugin %s", info.Name)) + panic(err) } scripts := make([]plugin.MigrationScript, 0) for _, script := range info.MigrationScripts { diff --git a/backend/test/helper/client.go b/backend/test/helper/client.go index 0970db916bf..840dbc25c17 100644 --- a/backend/test/helper/client.go +++ b/backend/test/helper/client.go @@ -172,7 +172,7 @@ func ConnectLocalServer(t *testing.T, clientConfig *LocalClientConfig) *DevlakeC cfg.Set("PLUGIN_DIR", throwawayDir) cfg.Set("LOGGING_DIR", throwawayDir) go func() { - initService.Do(api.CreateApiService) + initService.Do(func() { api.CreateApiService(nil) }) }() req, err2 := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/proceed-db-migration", addr), nil) require.NoError(t, err2)