You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
285 B
18 lines
285 B
2 months ago
|
package misc
|
||
|
|
||
|
import "encoding/json"
|
||
|
|
||
|
func Struct2Map(s any) (map[string]interface{}, error) {
|
||
|
str, err := json.Marshal(s)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
m := make(map[string]interface{})
|
||
|
if err = json.Unmarshal(str, &m); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return m, nil
|
||
|
}
|