首页 > 代码库 > golang struct转map

golang struct转map

struct转map

package main

import (
	"fmt"
	"reflect"
	"time"
)

type User struct {
	Id        int64
	Username  string
	Password  string
	Logintime time.Time
}

func Struct2Map(obj interface{}) map[string]interface{} {
	t := reflect.TypeOf(obj)
	v := reflect.ValueOf(obj)

	var data = http://www.mamicode.com/make(map[string]interface{})>