Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
  • Loading branch information
CabinfeverB committed Jan 30, 2024
1 parent 9204133 commit 43e35e4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 51 deletions.
17 changes: 0 additions & 17 deletions pkg/mcs/resourcemanager/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ import (
"net/http"
"reflect"
"strings"
"sync"
"testing"

"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/pingcap/log"
rmserver "github.com/tikv/pd/pkg/mcs/resourcemanager/server"
Expand All @@ -42,7 +39,6 @@ import (
const APIPathPrefix = "/resource-manager/api/v1/"

var (
once sync.Once
apiServiceGroup = apiutil.APIServiceGroup{
Name: "resource-manager",
Version: "v1",
Expand All @@ -56,14 +52,6 @@ func init() {
s := NewService(srv)
return s.handler(), apiServiceGroup
}
// refer https://github.com/tikv/pd/issues/7484
if testing.Testing() {
once.Do(func() {
// These global modification will be effective only for the first invoke.
_ = godotenv.Load()
gin.SetMode(gin.ReleaseMode)
})
}
}

// Service is the resource group service.
Expand All @@ -76,11 +64,6 @@ type Service struct {

// NewService returns a new Service.
func NewService(srv *rmserver.Service) *Service {
once.Do(func() {
// These global modification will be effective only for the first invoke.
_ = godotenv.Load()
gin.SetMode(gin.ReleaseMode)
})
apiHandlerEngine := gin.New()
apiHandlerEngine.Use(gin.Recovery())
apiHandlerEngine.Use(cors.Default())
Expand Down
17 changes: 0 additions & 17 deletions pkg/mcs/scheduling/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ import (
"net/url"
"strconv"
"strings"
"sync"
"testing"

"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
scheserver "github.com/tikv/pd/pkg/mcs/scheduling/server"
Expand All @@ -52,7 +49,6 @@ const APIPathPrefix = "/scheduling/api/v1"
const handlerKey = "handler"

var (
once sync.Once
apiServiceGroup = apiutil.APIServiceGroup{
Name: "scheduling",
Version: "v1",
Expand All @@ -66,14 +62,6 @@ func init() {
s := NewService(srv)
return s.apiHandlerEngine, apiServiceGroup
}
// refer https://github.com/tikv/pd/issues/7484
if testing.Testing() {
once.Do(func() {
// These global modification will be effective only for the first invoke.
_ = godotenv.Load()
gin.SetMode(gin.ReleaseMode)
})
}
}

// Service is the tso service.
Expand Down Expand Up @@ -101,11 +89,6 @@ func createIndentRender() *render.Render {

// NewService returns a new Service.
func NewService(srv *scheserver.Service) *Service {
once.Do(func() {
// These global modification will be effective only for the first invoke.
_ = godotenv.Load()
gin.SetMode(gin.ReleaseMode)
})
apiHandlerEngine := gin.New()
apiHandlerEngine.Use(gin.Recovery())
apiHandlerEngine.Use(cors.Default())
Expand Down
17 changes: 0 additions & 17 deletions pkg/mcs/tso/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ import (
"fmt"
"net/http"
"strconv"
"sync"
"testing"

"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/pingcap/kvproto/pkg/tsopb"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
Expand All @@ -45,7 +42,6 @@ const (
)

var (
once sync.Once
apiServiceGroup = apiutil.APIServiceGroup{
Name: "tso",
Version: "v1",
Expand All @@ -59,14 +55,6 @@ func init() {
s := NewService(srv)
return s.apiHandlerEngine, apiServiceGroup
}
// refer https://github.com/tikv/pd/issues/7484
if testing.Testing() {
once.Do(func() {
// These global modification will be effective only for the first invoke.
_ = godotenv.Load()
gin.SetMode(gin.ReleaseMode)
})
}
}

// Service is the tso service.
Expand All @@ -86,11 +74,6 @@ func createIndentRender() *render.Render {

// NewService returns a new Service.
func NewService(srv *tsoserver.Service) *Service {
once.Do(func() {
// These global modification will be effective only for the first invoke.
_ = godotenv.Load()
gin.SetMode(gin.ReleaseMode)
})
apiHandlerEngine := gin.New()
apiHandlerEngine.Use(gin.Recovery())
apiHandlerEngine.Use(cors.Default())
Expand Down
13 changes: 13 additions & 0 deletions pkg/utils/apiutil/apiutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"

"github.com/gin-gonic/gin"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
"github.com/pingcap/errcode"
"github.com/pingcap/errors"
"github.com/pingcap/log"
Expand Down Expand Up @@ -67,6 +70,16 @@ const (
chunkSize = 4096
)

var once sync.Once

func init() {
once.Do(func() {
// These global modification will be effective only for the first invoke.
_ = godotenv.Load()
gin.SetMode(gin.ReleaseMode)
})
}

// DeferClose captures the error returned from closing (if an error occurs).
// This is designed to be used in a defer statement.
func DeferClose(c io.Closer, err *error) {
Expand Down

0 comments on commit 43e35e4

Please sign in to comment.