mirror of
https://github.com/go-kratos/kratos.git
synced 2024-12-28 21:09:04 +02:00
cleanup: remove redundancy type conversion and golangci add unconvert (#2409)
* cleanup: remove redundancy type conversion * golangci add unconvert check
This commit is contained in:
parent
a680321309
commit
9f65c1a03d
@ -31,6 +31,7 @@ linters:
|
||||
- varcheck
|
||||
- whitespace
|
||||
- wastedassign
|
||||
- unconvert
|
||||
|
||||
# don't enable:
|
||||
# - asciicheck
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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`)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -25,7 +25,7 @@ func TestCodec_Marshal(t *testing.T) {
|
||||
// Test value types
|
||||
{Value: &Plain{true}, ExpectXML: `<Plain><V>true</V></Plain>`},
|
||||
{Value: &Plain{false}, ExpectXML: `<Plain><V>false</V></Plain>`},
|
||||
{Value: &Plain{int(42)}, ExpectXML: `<Plain><V>42</V></Plain>`},
|
||||
{Value: &Plain{42}, ExpectXML: `<Plain><V>42</V></Plain>`},
|
||||
{
|
||||
Value: &NestedOrder{Field1: "C", Field2: "B", Field3: "A"},
|
||||
ExpectXML: `<result>` +
|
||||
|
Loading…
Reference in New Issue
Block a user