2022-05-14 15:22:53 +08:00
|
|
|
// Package util ...
|
2022-05-14 13:45:51 +08:00
|
|
|
//
|
|
|
|
// Description : util ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2021-03-14 11:11 下午
|
|
|
|
package util
|
|
|
|
|
|
|
|
import "encoding/json"
|
|
|
|
|
2022-05-14 15:22:53 +08:00
|
|
|
// ownStruct ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 15:19 2022/5/14
|
|
|
|
type ownStruct struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToMap 结构体转为map
|
2022-05-14 13:45:51 +08:00
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 11:12 下午 2021/3/14
|
2022-05-14 15:22:53 +08:00
|
|
|
func (os *ownStruct) ToMap(data interface{}) (map[string]interface{}, error) {
|
2022-05-14 13:45:51 +08:00
|
|
|
var (
|
|
|
|
byteData []byte
|
|
|
|
err error
|
|
|
|
result map[string]interface{}
|
|
|
|
)
|
|
|
|
if byteData, err = json.Marshal(data); nil != err {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err = json.Unmarshal(byteData, &result); nil != err {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|