SkuName.Upc改为*string(以支持null及添加唯一索引)

This commit is contained in:
gazebo
2019-12-23 16:15:14 +08:00
parent 23136cc467
commit 01247221c4
4 changed files with 78 additions and 26 deletions

View File

@@ -92,5 +92,14 @@ func FilterMapByFieldList(mapData map[string]interface{}, fields []string) (vali
}
func IsValueEqual(value1, value2 interface{}) bool {
return fmt.Sprint(value1) == fmt.Sprint(value2)
return Interface2String(value1) == Interface2String(value2)
}
func Interface2String(value interface{}) (str string) {
valueType := reflect.TypeOf(value)
if valueType.Kind() == reflect.Ptr {
value = reflect.ValueOf(value).Elem()
}
str = fmt.Sprint(value)
return str
}

View File

@@ -0,0 +1,37 @@
package refutil
import (
"testing"
"git.rosy.net.cn/baseapi/utils"
)
func TestIsValueEqual(t *testing.T) {
for _, v := range [][]interface{}{
[]interface{}{
false,
1,
"1.0",
},
[]interface{}{
true,
"1",
utils.String2Pointer("1"),
},
[]interface{}{
true,
"1",
1,
},
[]interface{}{
true,
int64(100),
int(100),
},
} {
result := IsValueEqual(v[1], v[2])
if result != v[0].(bool) {
t.Fatalf("%v,%v, desired:%v, get:%v", v[1], v[2], v[0], result)
}
}
}