package util

import (
	"net/http"
	"strconv"
)

//数据类型转换
func GetPostForm(r *http.Request) map[string]interface{} {
	val := map[string]interface{}{}
	for k, _ := range r.Form {
		if len(k) < 2 {
			continue
		}
		if k != "_id" {
			v := r.FormValue(k)
			switch k[:2] {
			case "s_": //string型
				val[k] = v
			case "l_": //int64位
				val[k], _ = strconv.ParseInt(v, 10, 64)
			case "i_": //int型
				val[k], _ = strconv.Atoi(v)
			default:
				if v == "true" || v == "false" {
					b, _ := strconv.ParseBool(v)
					val[k] = b
				} else {
					val[k] = v
				}
			}
		}
	}
	return val
}
