This is an automated email from the ASF dual-hosted git repository. klesh pushed a commit to branch kw-saas-cognito in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 94ca4a00b7aa06cdc3fce52d3aa725ce916c2047 Author: Klesh Wong <[email protected]> AuthorDate: Thu Dec 7 11:43:35 2023 +0800 refactor: added CreateAndRunApiServer --- backend/server/api/api.go | 24 ++++++++++++++---------- backend/server/main.go | 2 +- backend/test/helper/client.go | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/backend/server/api/api.go b/backend/server/api/api.go index 698e9e1c9..0ee5021c1 100644 --- a/backend/server/api/api.go +++ b/backend/server/api/api.go @@ -32,7 +32,6 @@ import ( ginSwagger "github.com/swaggo/gin-swagger" "github.com/swaggo/swag" - "github.com/apache/incubator-devlake/core/config" "github.com/apache/incubator-devlake/core/errors" "github.com/apache/incubator-devlake/core/plugin" "github.com/apache/incubator-devlake/impls/logruslog" @@ -56,17 +55,19 @@ Alternatively, you may downgrade back to the previous DevLake version. // @license.name Apache-2.0 // @host localhost:8080 // @BasePath / -func CreateApiService(router *gin.Engine) { - // Get configuration - v := config.GetConfig() +func CreateAndRunApiServer() { + // Create router + router := gin.New() + // Setup and run the server + SetupApiServer(router) + RunApiServer(router) +} + +func SetupApiServer(router *gin.Engine) { // Initialize services services.Init() // Set gin mode - gin.SetMode(v.GetString("MODE")) - // Create a gin router - if router == nil { - router = gin.Default() - } + gin.SetMode(services.GetBasicRes().GetConfig("MODE")) // For both protected and unprotected routes router.GET("/ping", ping.Get) @@ -136,8 +137,11 @@ func CreateApiService(router *gin.Engine) { // Register API endpoints RegisterRouter(router, basicRes) +} + +func RunApiServer(router *gin.Engine) { // Get port from config - port := v.GetString("PORT") + port := services.GetBasicRes().GetConfig("PORT") // Trim any : from the start port = strings.TrimLeft(port, ":") // Convert to int diff --git a/backend/server/main.go b/backend/server/main.go index 514a179e6..664eaf0b8 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(nil) + api.CreateAndRunApiServer() } diff --git a/backend/test/helper/client.go b/backend/test/helper/client.go index 840dbc25c..dcc30cba2 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(func() { api.CreateApiService(nil) }) + initService.Do(func() { api.CreateAndRunApiServer() }) }() req, err2 := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/proceed-db-migration", addr), nil) require.NoError(t, err2)
