Add ToPointer,ToSlicePointer,ToSlice func (#36)

* Add ToPointer func

* Add ToSlice and ToSlicePointer func

Co-authored-by: zhanghu <305835360@qq.com>
This commit is contained in:
tangqiu0205andzhanghu authored and GitHub committed 2022-07-05 19:15:54 +08:00
1 parent fc0e104591
commit bab0a27e40
4 files changed
+48

No files matched your search

+5
View File
@@ -170,6 +170,11 @@ func ToInt(value any) (int64, error) {
}
}
// ToPointer returns a pointer to this value
func ToPointer[T any](value T) *T {
return &value
}
// StructToMap convert struct to map, only convert exported struct field
// map key is specified same as struct field tag `json` value
func StructToMap(value any) (map[string]any, error) {
+7
View File
@@ -178,3 +178,10 @@ func TestColorRGBToHex(t *testing.T) {
assert := internal.NewAssert(t, "TestColorRGBToHex")
assert.Equal(expected, colorHex)
}
func TestToPointer(t *testing.T) {
assert := internal.NewAssert(t, "TestToPointer")
result := ToPointer[int](123)
assert.Equal(*result, 123)
}