From d0ec9b5b2fc31d41c4cd15862654d03d22d1261e Mon Sep 17 00:00:00 2001 From: Cabinfever_B Date: Tue, 30 Jan 2024 16:16:53 +0800 Subject: [PATCH] address comment Signed-off-by: Cabinfever_B --- pkg/utils/apiutil/apiutil.go | 1 + server/apiv2/router.go | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/pkg/utils/apiutil/apiutil.go b/pkg/utils/apiutil/apiutil.go index 103db03aab1..65a3c04d7c1 100644 --- a/pkg/utils/apiutil/apiutil.go +++ b/pkg/utils/apiutil/apiutil.go @@ -74,6 +74,7 @@ var once sync.Once func init() { once.Do(func() { + // See https://github.com/pingcap/tidb-dashboard/blob/f8ecb64e3d63f4ed91c3dca7a04362418ade01d8/pkg/apiserver/apiserver.go#L84 // These global modification will be effective only for the first invoke. _ = godotenv.Load() gin.SetMode(gin.ReleaseMode) diff --git a/server/apiv2/router.go b/server/apiv2/router.go index fd3ce38c0e4..781a1cca87b 100644 --- a/server/apiv2/router.go +++ b/server/apiv2/router.go @@ -17,18 +17,14 @@ package apiv2 import ( "context" "net/http" - "sync" "github.com/gin-gonic/gin" - "github.com/joho/godotenv" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/server" "github.com/tikv/pd/server/apiv2/handlers" "github.com/tikv/pd/server/apiv2/middlewares" ) -var once sync.Once - var group = apiutil.APIServiceGroup{ Name: "core", IsCore: true, @@ -49,12 +45,6 @@ const apiV2Prefix = "/pd/api/v2/" // @license.url http://www.apache.org/licenses/LICENSE-2.0.html // @BasePath /pd/api/v2 func NewV2Handler(_ context.Context, svr *server.Server) (http.Handler, apiutil.APIServiceGroup, error) { - once.Do(func() { - // See https://github.com/pingcap/tidb-dashboard/blob/f8ecb64e3d63f4ed91c3dca7a04362418ade01d8/pkg/apiserver/apiserver.go#L84 - // These global modification will be effective only for the first invoke. - _ = godotenv.Load() - gin.SetMode(gin.ReleaseMode) - }) router := gin.New() router.Use(func(c *gin.Context) { c.Set(middlewares.ServerContextKey, svr)