Repository: zeromicro/go-zero
Pull request #1871 (2022-05-06 06:17:27)

chore: fix deprecated usages


Patch:
diff --git a/core/logx/rotatelogger.go b/core/logx/rotatelogger.go
index a7b8ea72..bd31ce7e 100644
--- a/core/logx/rotatelogger.go
+++ b/core/logx/rotatelogger.go
@@ -292,7 +292,7 @@ func compressLogFile(file string) {
 	start := time.Now()
 	Infof("compressing log file: %s", file)
 	if err := gzipFile(file); err != nil {
-		Errorf("compress error: %s", err)
+		ErrorStackf("compress error: %s", err)
 	} else {
 		Infof("compressed log file: %s, took %s", file, time.Since(start))
 	}


Test patch:
diff --git a/core/logx/rotatelogger_test.go b/core/logx/rotatelogger_test.go
index 5bb1d58f..a7486d95 100644
--- a/core/logx/rotatelogger_test.go
+++ b/core/logx/rotatelogger_test.go
@@ -75,10 +75,7 @@ func TestRotateLoggerMayCompressFileTrue(t *testing.T) {
 	logger, err := NewLogger(filename, new(DailyRotateRule), true)
 	assert.Nil(t, err)
 	if len(filename) > 0 {
-		defer func() {
-			os.Remove(filename)
-			os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz")
-		}()
+		defer os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz")
 	}
 	logger.maybeCompressFile(filename)
 	_, err = os.Stat(filename)
@@ -92,7 +89,6 @@ func TestRotateLoggerRotate(t *testing.T) {
 	assert.Nil(t, err)
 	if len(filename) > 0 {
 		defer func() {
-			os.Remove(filename)
 			os.Remove(logger.getBackupFilename())
 			os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz")
 		}()
@@ -115,7 +111,6 @@ func TestRotateLoggerWrite(t *testing.T) {
 	assert.Nil(t, err)
 	if len(filename) > 0 {
 		defer func() {
-			os.Remove(filename)
 			os.Remove(logger.getBackupFilename())
 			os.Remove(filepath.Base(logger.getBackupFilename()) + ".gz")
 		}()
diff --git a/rest/engine_test.go b/rest/engine_test.go
index 8b8ff528..a8df1dd9 100644
--- a/rest/engine_test.go
+++ b/rest/engine_test.go
@@ -146,7 +146,7 @@ Verbose: true
 	for _, yaml := range yamls {
 		for _, route := range routes {
 			var cnf RestConf
-			assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(yaml), &cnf))
+			assert.Nil(t, conf.LoadFromYamlBytes([]byte(yaml), &cnf))
 			ng := newEngine(cnf)
 			ng.addRoutes(route)
 			ng.use(func(next http.HandlerFunc) http.HandlerFunc {
@@ -300,15 +300,15 @@ func TestEngine_notFoundHandlerNotNilWriteHeader(t *testing.T) {
 
 type mockedRouter struct{}
 
-func (m mockedRouter) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
+func (m mockedRouter) ServeHTTP(_ http.ResponseWriter, _ *http.Request) {
 }
 
-func (m mockedRouter) Handle(method, path string, handler http.Handler) error {
+func (m mockedRouter) Handle(_, _ string, _ http.Handler) error {
 	return errors.New("foo")
 }
 
-func (m mockedRouter) SetNotFoundHandler(handler http.Handler) {
+func (m mockedRouter) SetNotFoundHandler(_ http.Handler) {
 }
 
-func (m mockedRouter) SetNotAllowedHandler(handler http.Handler) {
+func (m mockedRouter) SetNotAllowedHandler(_ http.Handler) {
 }
diff --git a/rest/server_test.go b/rest/server_test.go
index c1c655c9..4d4d21be 100644
--- a/rest/server_test.go
+++ b/rest/server_test.go
@@ -21,7 +21,7 @@ Name: foo
 Port: 54321
 `
 	var cnf RestConf
-	assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
+	assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf))
 
 	tests := []struct {
 		c    RestConf
@@ -271,7 +271,7 @@ Name: foo
 Port: 54321
 `
 	var cnf RestConf
-	assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
+	assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf))
 
 	testConfig := &tls.Config{
 		CipherSuites: []uint16{
@@ -309,7 +309,7 @@ Name: foo
 Port: 54321
 `
 	var cnf RestConf
-	assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
+	assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf))
 	rt := router.NewRouter()
 	svr, err := NewServer(cnf, WithRouter(rt))
 	assert.Nil(t, err)
@@ -324,7 +324,7 @@ Name: foo
 Port: 54321
 `
 	var cnf RestConf
-	assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
+	assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf))
 	rt := router.NewRouter()
 	svr, err := NewServer(cnf, WithRouter(rt))
 	assert.Nil(t, err)