mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
30 lines
527 B
Go
30 lines
527 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
func ToMap(rec interface{}) (map[string]interface{}, error) {
|
|
// Convert to JSON...
|
|
b, err := json.Marshal(rec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// ... then convert to map
|
|
var m map[string]interface{}
|
|
err = json.Unmarshal(b, &m)
|
|
return m, err
|
|
}
|
|
|
|
func ToStruct(m map[string]interface{}, rec interface{}) error {
|
|
// Convert to JSON...
|
|
b, err := json.Marshal(m)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// ... then convert to struct
|
|
err = json.Unmarshal(b, &rec)
|
|
return err
|
|
}
|