package utils

import (
	"reflect"
)

// Map2Struct map 转 struct
// 必须保证 s 为 stuct 指针
func Map2Struct(m map[string]interface{}, s interface{}) {
	sv := reflect.ValueOf(s).Elem()

	for k, t := range m {
		f := sv.FieldByName(k)

		if !f.IsValid() {
			continue
		}

		switch v := t.(type) {
		case string:
			f.SetString(v)
		case float64:
			f.SetInt(int64(v))
		default:
			continue
		}
	}
}
