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.
31 lines
440 B
31 lines
440 B
package misc
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
func Map2Struct(m map[string]interface{}, s any) error {
|
|
str, err := json.Marshal(m)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := json.Unmarshal(str, s); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Map2Struct4HB(m map[string][]byte, s any) error {
|
|
str, err := json.Marshal(m)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := json.Unmarshal(str, s); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|