28 lines
553 B
Go
28 lines
553 B
Go
|
package laniakea
|
||
|
|
||
|
import "encoding/json"
|
||
|
|
||
|
func MapToStruct(m map[string]interface{}, s interface{}) error {
|
||
|
data, err := json.Marshal(m)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
err = json.Unmarshal(data, s)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func MapToJson(m map[string]interface{}) (string, error) {
|
||
|
data, err := json.Marshal(m)
|
||
|
return string(data), err
|
||
|
}
|
||
|
|
||
|
func StructToMap(s interface{}) (map[string]interface{}, error) {
|
||
|
data, err := json.Marshal(s)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
m := make(map[string]interface{})
|
||
|
err = json.Unmarshal(data, &m)
|
||
|
return m, err
|
||
|
}
|