25 lines
403 B
Go
25 lines
403 B
Go
package util
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
)
|
|
|
|
// StructToMap 将struct转为map
|
|
func StructToMap(info any) map[string]any {
|
|
result := make(map[string]any)
|
|
data, err := json.Marshal(info)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
d := json.NewDecoder(bytes.NewReader(data))
|
|
d.UseNumber()
|
|
err = d.Decode(&result)
|
|
//err = json.Unmarshal(data, &result)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return result
|
|
}
|