func StructToMap(obj interface{}) map[string]interface{} {
	rt, rv := reflect.TypeOf(obj), reflect.ValueOf(obj)
	if rt != nil && rt.Kind() != reflect.Struct {
		return make(map[string]interface{}, 0)
	}

	out := make(map[string]interface{}, rt.NumField())
	for i := 0; i < rt.NumField(); i++ {
		field := rt.Field(i)

		// Unexported fields, access not allowed
		if field.PkgPath != "" {
			continue
		}

		var fieldName string
		if tagVal, ok := field.Tag.Lookup("json"); ok {
			// Honor the special "-" in json attribute
			if strings.HasPrefix(tagVal, "-") {
				continue
			}
			fieldName = tagVal
		} else {
			fieldName = field.Name
		}

		val := valueToInterface(rv.Field(i))
		if val != nil {
			out[fieldName] = val
		}
	}

	return out
}
// StructToMap converts a struct to a map[string]interface{} based on `json` annotations defaulting to field names
StructToMap converts a struct to a map[string]interface{} based on `json` annotations defaulting to field names
// StructToMap converts a struct to a map [ string ] interface {} based on ` json ` annotations defaulting to field names
func StructToMap(obj interface{}) map[string]interface{} {
	rt, rv := reflect.TypeOf(obj), reflect.ValueOf(obj)
	if rt != nil && rt.Kind() != reflect.Struct {
		return make(map[string]interface{}, 0)
	}
	out := make(map[string]interface{}, rt.NumField())
	for i := 0; i < rt.NumField(); i++ {
		field := rt.Field(i)
		if field.PkgPath != "" {
			continue
		}
		var fieldName string
		if tagVal, ok := field.Tag.Lookup("json"); ok {
			if strings.HasPrefix(tagVal, "-") {
				continue
			}
			fieldName = tagVal
		} else {
			fieldName = field.Name
		}
		val := valueToInterface(rv.Field(i))
		if val != nil {
			out[fieldName] = val
		}
	}
	return out
}
func StructToMap ( obj interface { } ) map [ string ] interface { } { rt , rv := reflect . TypeOf ( obj ) , reflect . ValueOf ( obj ) if rt != nil && rt . Kind ( ) != reflect . Struct { return make ( map [ string ] interface { } , 0 ) } out := make ( map [ string ] interface { } , rt . NumField ( ) ) for i := 0 ; i < rt . NumField ( ) ; i ++ { field := rt . Field ( i ) if field . PkgPath != " " { continue } var fieldName string if tagVal , ok := field . Tag . Lookup ( " " ) ; ok { if strings . HasPrefix ( tagVal , " " ) { continue } fieldName = tagVal } else { fieldName = field . Name } val := valueToInterface ( rv . Field ( i ) ) if val != nil { out [ fieldName ] = val } } return out }
StructToMap converts a struct to a map[string]interface{} based on `json` annotations defaulting to field names
StructToMap converts a struct to a map [ string ] interface {} based on ` json ` annotations defaulting to field names
// Unexported fields, access not allowed // Honor the special "-" in json attribute