mirror of
https://github.com/go-kratos/kratos.git
synced 2026-05-22 10:15:24 +02:00
fix: ci lint error (#1391)
* fix lint check * fix lll lint error * fix build error * fix gomnd * fix shadow declaration * add make test command * update
This commit is contained in:
@@ -10,8 +10,12 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Name is form codec name
|
||||
const Name = "x-www-form-urlencoded"
|
||||
const (
|
||||
// Name is form codec name
|
||||
Name = "x-www-form-urlencoded"
|
||||
// Null value string
|
||||
nullStr = "null"
|
||||
)
|
||||
|
||||
func init() {
|
||||
decoder := form.NewDecoder()
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestFormCodecMarshal(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []byte("username=kratos"), content)
|
||||
|
||||
m := TestModel{
|
||||
m := &TestModel{
|
||||
ID: 1,
|
||||
Name: "kratos",
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func TestFormCodecUnmarshal(t *testing.T) {
|
||||
content, err := encoding.GetCodec(contentType).Marshal(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var bindReq = new(LoginRequest)
|
||||
bindReq := new(LoginRequest)
|
||||
err = encoding.GetCodec(contentType).Unmarshal(content, bindReq)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "kratos", bindReq.Username)
|
||||
@@ -72,7 +72,7 @@ func TestProtoEncodeDecode(t *testing.T) {
|
||||
content, err := encoding.GetCodec(contentType).Marshal(in)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "id=2233&numberOne=2233&simples=3344&simples=5566&very_simple.component=5566", string(content))
|
||||
var in2 = &complex.Complex{}
|
||||
in2 := &complex.Complex{}
|
||||
err = encoding.GetCodec(contentType).Unmarshal(content, in2)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(2233), in2.Id)
|
||||
|
||||
@@ -105,7 +105,7 @@ func populateRepeatedField(fd protoreflect.FieldDescriptor, list protoreflect.Li
|
||||
}
|
||||
|
||||
func populateMapField(fd protoreflect.FieldDescriptor, mp protoreflect.Map, values []string) error {
|
||||
if len(values) != 2 {
|
||||
if len(values) != 2 { //nolint:gomnd
|
||||
return fmt.Errorf("more than one value provided for key %q in map %q", values[0], fd.FullName())
|
||||
}
|
||||
key, err := parseField(fd.MapKey(), values[0])
|
||||
@@ -138,7 +138,7 @@ func parseField(fd protoreflect.FieldDescriptor, value string) (protoreflect.Val
|
||||
}
|
||||
v := enum.Descriptor().Values().ByName(protoreflect.Name(value))
|
||||
if v == nil {
|
||||
i, err := strconv.ParseInt(value, 10, 32)
|
||||
i, err := strconv.ParseInt(value, 10, 32) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, fmt.Errorf("%q is not a valid value", value)
|
||||
}
|
||||
@@ -149,37 +149,37 @@ func parseField(fd protoreflect.FieldDescriptor, value string) (protoreflect.Val
|
||||
}
|
||||
return protoreflect.ValueOfEnum(v.Number()), nil
|
||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
|
||||
v, err := strconv.ParseInt(value, 10, 32)
|
||||
v, err := strconv.ParseInt(value, 10, 32) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
return protoreflect.ValueOfInt32(int32(v)), nil
|
||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
|
||||
v, err := strconv.ParseInt(value, 10, 64)
|
||||
v, err := strconv.ParseInt(value, 10, 64) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
return protoreflect.ValueOfInt64(v), nil
|
||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
|
||||
v, err := strconv.ParseUint(value, 10, 32)
|
||||
v, err := strconv.ParseUint(value, 10, 32) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
return protoreflect.ValueOfUint32(uint32(v)), nil
|
||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
|
||||
v, err := strconv.ParseUint(value, 10, 64)
|
||||
v, err := strconv.ParseUint(value, 10, 64) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
return protoreflect.ValueOfUint64(v), nil
|
||||
case protoreflect.FloatKind:
|
||||
v, err := strconv.ParseFloat(value, 32)
|
||||
v, err := strconv.ParseFloat(value, 32) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
return protoreflect.ValueOfFloat32(float32(v)), nil
|
||||
case protoreflect.DoubleKind:
|
||||
v, err := strconv.ParseFloat(value, 64)
|
||||
v, err := strconv.ParseFloat(value, 64) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
@@ -203,7 +203,7 @@ func parseMessage(md protoreflect.MessageDescriptor, value string) (protoreflect
|
||||
var msg proto.Message
|
||||
switch md.FullName() {
|
||||
case "google.protobuf.Timestamp":
|
||||
if value == "null" {
|
||||
if value == nullStr {
|
||||
break
|
||||
}
|
||||
t, err := time.Parse(time.RFC3339Nano, value)
|
||||
@@ -212,7 +212,7 @@ func parseMessage(md protoreflect.MessageDescriptor, value string) (protoreflect
|
||||
}
|
||||
msg = timestamppb.New(t)
|
||||
case "google.protobuf.Duration":
|
||||
if value == "null" {
|
||||
if value == nullStr {
|
||||
break
|
||||
}
|
||||
d, err := time.ParseDuration(value)
|
||||
@@ -221,37 +221,37 @@ func parseMessage(md protoreflect.MessageDescriptor, value string) (protoreflect
|
||||
}
|
||||
msg = durationpb.New(d)
|
||||
case "google.protobuf.DoubleValue":
|
||||
v, err := strconv.ParseFloat(value, 64)
|
||||
v, err := strconv.ParseFloat(value, 64) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
msg = wrapperspb.Double(v)
|
||||
case "google.protobuf.FloatValue":
|
||||
v, err := strconv.ParseFloat(value, 32)
|
||||
v, err := strconv.ParseFloat(value, 32) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
msg = wrapperspb.Float(float32(v))
|
||||
case "google.protobuf.Int64Value":
|
||||
v, err := strconv.ParseInt(value, 10, 64)
|
||||
v, err := strconv.ParseInt(value, 10, 64) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
msg = wrapperspb.Int64(v)
|
||||
case "google.protobuf.Int32Value":
|
||||
v, err := strconv.ParseInt(value, 10, 32)
|
||||
v, err := strconv.ParseInt(value, 10, 32) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
msg = wrapperspb.Int32(int32(v))
|
||||
case "google.protobuf.UInt64Value":
|
||||
v, err := strconv.ParseUint(value, 10, 64)
|
||||
v, err := strconv.ParseUint(value, 10, 64) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
msg = wrapperspb.UInt64(v)
|
||||
case "google.protobuf.UInt32Value":
|
||||
v, err := strconv.ParseUint(value, 10, 32)
|
||||
v, err := strconv.ParseUint(value, 10, 32) //nolint:gomnd
|
||||
if err != nil {
|
||||
return protoreflect.Value{}, err
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ func encodeField(fieldDescriptor protoreflect.FieldDescriptor, value protoreflec
|
||||
return strconv.FormatBool(value.Bool()), nil
|
||||
case protoreflect.EnumKind:
|
||||
if fieldDescriptor.Enum().FullName() == "google.protobuf.NullValue" {
|
||||
return "null", nil
|
||||
return nullStr, nil
|
||||
}
|
||||
desc := fieldDescriptor.Enum().Values().ByNumber(value.Enum())
|
||||
return string(desc.Name()), nil
|
||||
|
||||
Reference in New Issue
Block a user