Repository: zeromicro/go-zero
Pull request #2406 (2022-09-17 11:53:20)

chore: refactor the imports


Patch:
diff --git a/core/metric/counter.go b/core/metric/counter.go
index 578f91f9..c95412f7 100644
--- a/core/metric/counter.go
+++ b/core/metric/counter.go
@@ -1,10 +1,9 @@
 package metric
 
 import (
+	prom "github.com/prometheus/client_golang/prometheus"
 	"github.com/zeromicro/go-zero/core/proc"
 	"github.com/zeromicro/go-zero/core/prometheus"
-
-	prom "github.com/prometheus/client_golang/prometheus"
 )
 
 type (
diff --git a/core/metric/gauge.go b/core/metric/gauge.go
index 763bd4d9..52ff841d 100644
--- a/core/metric/gauge.go
+++ b/core/metric/gauge.go
@@ -1,10 +1,9 @@
 package metric
 
 import (
+	prom "github.com/prometheus/client_golang/prometheus"
 	"github.com/zeromicro/go-zero/core/proc"
 	"github.com/zeromicro/go-zero/core/prometheus"
-
-	prom "github.com/prometheus/client_golang/prometheus"
 )
 
 type (
diff --git a/core/metric/histogram.go b/core/metric/histogram.go
index 77cb5e39..4f0a1058 100644
--- a/core/metric/histogram.go
+++ b/core/metric/histogram.go
@@ -1,10 +1,9 @@
 package metric
 
 import (
+	prom "github.com/prometheus/client_golang/prometheus"
 	"github.com/zeromicro/go-zero/core/proc"
 	"github.com/zeromicro/go-zero/core/prometheus"
-
-	prom "github.com/prometheus/client_golang/prometheus"
 )
 
 type (
diff --git a/core/stores/redis/hook.go b/core/stores/redis/hook.go
index 4cd8e97c..5229bd27 100644
--- a/core/stores/redis/hook.go
+++ b/core/stores/redis/hook.go
@@ -57,7 +57,7 @@ func (h hook) AfterProcess(ctx context.Context, cmd red.Cmder) error {
 	}
 
 	metricReqDur.Observe(int64(duration/time.Millisecond), cmd.Name())
-	if msg := errFormat(err); len(msg) > 0 {
+	if msg := formatError(err); len(msg) > 0 {
 		metricReqErr.Inc(cmd.Name(), msg)
 	}
 
@@ -104,14 +104,14 @@ func (h hook) AfterProcessPipeline(ctx context.Context, cmds []red.Cmder) error
 	}
 
 	metricReqDur.Observe(int64(duration/time.Millisecond), "Pipeline")
-	if msg := errFormat(batchError.Err()); len(msg) > 0 {
+	if msg := formatError(batchError.Err()); len(msg) > 0 {
 		metricReqErr.Inc("Pipeline", msg)
 	}
 
 	return nil
 }
 
-func errFormat(err error) string {
+func formatError(err error) string {
 	if err == nil || err == red.Nil {
 		return ""
 	}
diff --git a/core/stores/sqlx/metrics.go b/core/stores/sqlx/metrics.go
index 3a4c7e0b..7c478012 100644
--- a/core/stores/sqlx/metrics.go
+++ b/core/stores/sqlx/metrics.go
@@ -2,7 +2,7 @@ package sqlx
 
 import "github.com/zeromicro/go-zero/core/metric"
 
-const namespace = "mysql_client"
+const namespace = "sql_client"
 
 var (
 	metricReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{
diff --git a/core/stores/sqlx/sqlconn.go b/core/stores/sqlx/sqlconn.go
index e5771c54..0118a38d 100644
--- a/core/stores/sqlx/sqlconn.go
+++ b/core/stores/sqlx/sqlconn.go
@@ -153,7 +153,6 @@ func (db *commonSqlConn) ExecCtx(ctx context.Context, q string, args ...interfac
 		result, err = exec(ctx, conn, q, args...)
 		return err
 	}, db.acceptable)
-
 	if err == breaker.ErrServiceUnavailable {
 		metricReqErr.Inc("Exec", "breaker")
 	}
@@ -190,7 +189,6 @@ func (db *commonSqlConn) PrepareCtx(ctx context.Context, query string) (stmt Stm
 		}
 		return nil
 	}, db.acceptable)
-
 	if err == breaker.ErrServiceUnavailable {
 		metricReqErr.Inc("Prepare", "breaker")
 	}
@@ -281,7 +279,6 @@ func (db *commonSqlConn) TransactCtx(ctx context.Context, fn func(context.Contex
 	err = db.brk.DoWithAcceptable(func() error {
 		return transact(ctx, db, db.beginTx, fn)
 	}, db.acceptable)
-
 	if err == breaker.ErrServiceUnavailable {
 		metricReqErr.Inc("Transact", "breaker")
 	}
@@ -315,7 +312,6 @@ func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows)
 	}, func(err error) bool {
 		return qerr == err || db.acceptable(err)
 	})
-
 	if err == breaker.ErrServiceUnavailable {
 		metricReqErr.Inc("queryRows", "breaker")
 	}
diff --git a/zrpc/internal/clientinterceptors/prometheusinterceptor.go b/zrpc/internal/clientinterceptors/prometheusinterceptor.go
index 56017053..7b50144a 100644
--- a/zrpc/internal/clientinterceptors/prometheusinterceptor.go
+++ b/zrpc/internal/clientinterceptors/prometheusinterceptor.go
@@ -7,7 +7,6 @@ import (
 
 	"github.com/zeromicro/go-zero/core/metric"
 	"github.com/zeromicro/go-zero/core/timex"
-
 	"google.golang.org/grpc"
 	"google.golang.org/grpc/status"
 )
diff --git a/zrpc/internal/serverinterceptors/prometheusinterceptor.go b/zrpc/internal/serverinterceptors/prometheusinterceptor.go
index 97ac073e..e6cce1a4 100644
--- a/zrpc/internal/serverinterceptors/prometheusinterceptor.go
+++ b/zrpc/internal/serverinterceptors/prometheusinterceptor.go
@@ -7,7 +7,6 @@ import (
 
 	"github.com/zeromicro/go-zero/core/metric"
 	"github.com/zeromicro/go-zero/core/timex"
-
 	"google.golang.org/grpc"
 	"google.golang.org/grpc/status"
 )


Test patch:
diff --git a/core/metric/counter_test.go b/core/metric/counter_test.go
index 64cb5056..145d1b20 100644
--- a/core/metric/counter_test.go
+++ b/core/metric/counter_test.go
@@ -3,10 +3,9 @@ package metric
 import (
 	"testing"
 
-	"github.com/zeromicro/go-zero/core/prometheus"
-
 	"github.com/prometheus/client_golang/prometheus/testutil"
 	"github.com/stretchr/testify/assert"
+	"github.com/zeromicro/go-zero/core/prometheus"
 )
 
 func TestNewCounterVec(t *testing.T) {