18 lines
321 B
Go
18 lines
321 B
Go
|
package utils
|
||
|
|
||
|
import "reflect"
|
||
|
|
||
|
// ToMap struct to map[string]interface{}
|
||
|
func ToMap(ss interface{}) map[string]interface{} {
|
||
|
t := reflect.ValueOf(ss).Elem()
|
||
|
|
||
|
smap := make(map[string]interface{})
|
||
|
|
||
|
for i := 0; i < t.NumField(); i++ {
|
||
|
f := t.Field(i)
|
||
|
smap[t.Type().Field(i).Name] = f.Interface()
|
||
|
}
|
||
|
|
||
|
return smap
|
||
|
}
|