1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-15 02:02:27 +08:00

fix: fix lint issue

This commit is contained in:
dudaodong
2022-12-10 16:41:40 +08:00
parent 2725575d2f
commit 13bbe19ab2
17 changed files with 142 additions and 98 deletions

View File

@@ -97,38 +97,41 @@ func ToString(value any) string {
return ""
}
switch value.(type) {
switch val := value.(type) {
case float32:
return strconv.FormatFloat(float64(value.(float32)), 'f', -1, 32)
return strconv.FormatFloat(float64(val), 'f', -1, 32)
case float64:
return strconv.FormatFloat(value.(float64), 'f', -1, 64)
return strconv.FormatFloat(val, 'f', -1, 64)
case int:
return strconv.FormatInt(int64(value.(int)), 10)
return strconv.FormatInt(int64(val), 10)
case int8:
return strconv.FormatInt(int64(value.(int8)), 10)
return strconv.FormatInt(int64(val), 10)
case int16:
return strconv.FormatInt(int64(value.(int16)), 10)
return strconv.FormatInt(int64(val), 10)
case int32:
return strconv.FormatInt(int64(value.(int32)), 10)
return strconv.FormatInt(int64(val), 10)
case int64:
return strconv.FormatInt(value.(int64), 10)
return strconv.FormatInt(val, 10)
case uint:
return strconv.FormatUint(uint64(value.(uint)), 10)
return strconv.FormatUint(uint64(val), 10)
case uint8:
return strconv.FormatUint(uint64(value.(uint8)), 10)
return strconv.FormatUint(uint64(val), 10)
case uint16:
return strconv.FormatUint(uint64(value.(uint16)), 10)
return strconv.FormatUint(uint64(val), 10)
case uint32:
return strconv.FormatUint(uint64(value.(uint32)), 10)
return strconv.FormatUint(uint64(val), 10)
case uint64:
return strconv.FormatUint(value.(uint64), 10)
return strconv.FormatUint(val, 10)
case string:
return value.(string)
return val
case []byte:
return string(value.([]byte))
return string(val)
default:
newValue, _ := json.Marshal(value)
return string(newValue)
b, err := json.Marshal(val)
if err != nil {
return ""
}
return string(b)
// todo: maybe we should't supprt other type conversion
// v := reflect.ValueOf(value)

View File

@@ -27,14 +27,9 @@ func TestToChannel(t *testing.T) {
assert := internal.NewAssert(t, "TestToChannel")
ch := ToChannel([]int{1, 2, 3})
val1, _ := <-ch
assert.Equal(1, val1)
val2, _ := <-ch
assert.Equal(2, val2)
val3, _ := <-ch
assert.Equal(3, val3)
assert.Equal(1, <-ch)
assert.Equal(2, <-ch)
assert.Equal(3, <-ch)
_, ok := <-ch
assert.Equal(false, ok)
@@ -254,6 +249,7 @@ func TestDecodeByte(t *testing.T) {
var obj string
byteData := []byte{6, 12, 0, 3, 97, 98, 99}
DecodeByte(byteData, &obj)
err := DecodeByte(byteData, &obj)
assert.IsNil(err)
assert.Equal("abc", obj)
}