From 9f65c1a03d6bb9923e65d61de7853e8faa48b23f Mon Sep 17 00:00:00 2001
From: "jesse.tang" <1430482733@qq.com>
Date: Mon, 10 Oct 2022 11:19:39 +0800
Subject: [PATCH] cleanup: remove redundancy type conversion and golangci add
unconvert (#2409)
* cleanup: remove redundancy type conversion
* golangci add unconvert check
---
.golangci.yml | 1 +
api/metadata/server.go | 2 +-
config/file/file_test.go | 2 +-
config/value_test.go | 4 ++--
contrib/config/consul/config.go | 4 ++--
contrib/log/aliyun/aliyun.go | 2 +-
contrib/log/tencent/tencent.go | 2 +-
encoding/form/proto_encode.go | 2 +-
encoding/xml/xml_test.go | 2 +-
9 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/.golangci.yml b/.golangci.yml
index 441db5ee5..99d8b2ce6 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -31,6 +31,7 @@ linters:
- varcheck
- whitespace
- wastedassign
+ - unconvert
# don't enable:
# - asciicheck
diff --git a/api/metadata/server.go b/api/metadata/server.go
index 39e468ec5..3600fc14e 100644
--- a/api/metadata/server.go
+++ b/api/metadata/server.go
@@ -14,7 +14,7 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
- protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
dpb "google.golang.org/protobuf/types/descriptorpb"
diff --git a/config/file/file_test.go b/config/file/file_test.go
index d3c55ad39..0eb2b24fc 100644
--- a/config/file/file_test.go
+++ b/config/file/file_test.go
@@ -208,7 +208,7 @@ func TestConfig(t *testing.T) {
func testConfig(t *testing.T, c config.Config) {
expected := map[string]interface{}{
"test.settings.int_key": int64(1000),
- "test.settings.float_key": float64(1000.1),
+ "test.settings.float_key": 1000.1,
"test.settings.string_key": "string_value",
"test.settings.duration_key": time.Duration(10000),
"test.server.addr": "127.0.0.1",
diff --git a/config/value_test.go b/config/value_test.go
index 9f6745380..68558bf81 100644
--- a/config/value_test.go
+++ b/config/value_test.go
@@ -70,7 +70,7 @@ func Test_atomicValue_Int(t *testing.T) {
}
func Test_atomicValue_Float(t *testing.T) {
- vlist := []interface{}{"123123.1", float64(123123.1)}
+ vlist := []interface{}{"123123.1", 123123.1}
for _, x := range vlist {
v := atomicValue{}
v.Store(x)
@@ -78,7 +78,7 @@ func Test_atomicValue_Float(t *testing.T) {
if err != nil {
t.Fatal(`err is not nil`)
}
- if b != float64(123123.1) {
+ if b != 123123.1 {
t.Fatal(`b is not equal to 123123.1`)
}
}
diff --git a/contrib/config/consul/config.go b/contrib/config/consul/config.go
index dca8a88e7..0404801bc 100644
--- a/contrib/config/consul/config.go
+++ b/contrib/config/consul/config.go
@@ -28,9 +28,9 @@ func WithContext(ctx context.Context) Option {
// WithPath is config path
func WithPath(p string) Option {
- return Option(func(o *options) {
+ return func(o *options) {
o.path = p
- })
+ }
}
type source struct {
diff --git a/contrib/log/aliyun/aliyun.go b/contrib/log/aliyun/aliyun.go
index 83219fc12..351de69d9 100644
--- a/contrib/log/aliyun/aliyun.go
+++ b/contrib/log/aliyun/aliyun.go
@@ -10,7 +10,7 @@ import (
"github.com/aliyun/aliyun-log-go-sdk/producer"
"google.golang.org/protobuf/proto"
- log "github.com/go-kratos/kratos/v2/log"
+ "github.com/go-kratos/kratos/v2/log"
)
// Logger see more detail https://github.com/aliyun/aliyun-log-go-sdk
diff --git a/contrib/log/tencent/tencent.go b/contrib/log/tencent/tencent.go
index 5e0719d2c..8becf7883 100644
--- a/contrib/log/tencent/tencent.go
+++ b/contrib/log/tencent/tencent.go
@@ -9,7 +9,7 @@ import (
cls "github.com/tencentcloud/tencentcloud-cls-sdk-go"
"google.golang.org/protobuf/proto"
- log "github.com/go-kratos/kratos/v2/log"
+ "github.com/go-kratos/kratos/v2/log"
)
type Logger interface {
diff --git a/encoding/form/proto_encode.go b/encoding/form/proto_encode.go
index 28ebb0bc1..94eac6ab8 100644
--- a/encoding/form/proto_encode.go
+++ b/encoding/form/proto_encode.go
@@ -162,7 +162,7 @@ func encodeMessage(msgDescriptor protoreflect.MessageDescriptor, value protorefl
case "google.protobuf.DoubleValue", "google.protobuf.FloatValue", "google.protobuf.Int64Value", "google.protobuf.Int32Value",
"google.protobuf.UInt64Value", "google.protobuf.UInt32Value", "google.protobuf.BoolValue", "google.protobuf.StringValue":
fd := msgDescriptor.Fields()
- v := value.Message().Get(fd.ByName(protoreflect.Name("value")))
+ v := value.Message().Get(fd.ByName("value"))
return fmt.Sprint(v.Interface()), nil
case fieldMaskFullName:
m, ok := value.Message().Interface().(*fieldmaskpb.FieldMask)
diff --git a/encoding/xml/xml_test.go b/encoding/xml/xml_test.go
index 6c53c3dd0..09e7d03b9 100644
--- a/encoding/xml/xml_test.go
+++ b/encoding/xml/xml_test.go
@@ -25,7 +25,7 @@ func TestCodec_Marshal(t *testing.T) {
// Test value types
{Value: &Plain{true}, ExpectXML: `true`},
{Value: &Plain{false}, ExpectXML: `false`},
- {Value: &Plain{int(42)}, ExpectXML: `42`},
+ {Value: &Plain{42}, ExpectXML: `42`},
{
Value: &NestedOrder{Field1: "C", Field2: "B", Field3: "A"},
ExpectXML: `` +