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

doc: update doc

This commit is contained in:
dudaodong
2024-09-04 10:21:46 +08:00
2 changed files with 7 additions and 2 deletions

View File

@@ -197,6 +197,7 @@ func StructToMap(value interface{}) (map[string]interface{}, error) {
if t.Kind() == reflect.Ptr { if t.Kind() == reflect.Ptr {
t = t.Elem() t = t.Elem()
v = v.Elem()
} }
if t.Kind() != reflect.Struct { if t.Kind() != reflect.Struct {
return nil, fmt.Errorf("data type %T not support, shuld be struct or pointer to struct", value) return nil, fmt.Errorf("data type %T not support, shuld be struct or pointer to struct", value)

View File

@@ -156,13 +156,17 @@ func TestStructToMap(t *testing.T) {
Name string `json:"name"` Name string `json:"name"`
age int age int
} }
p := People{ p := &People{
"test", "test",
100, 100,
} }
pm, _ := StructToMap(p) pm, _ := StructToMap(p)
var expected = map[string]interface{}{"name": "test"} data, _ := StructToMap(p)
var expected = map[string]interface{}{
"name": "test",
}
assert.Equal(expected, pm) assert.Equal(expected, pm)
assert.Equal(expected, data)
} }
func TestColorHexToRGB(t *testing.T) { func TestColorHexToRGB(t *testing.T) {