Type string
Name string
DBName string
+ DBType string
Label string
Value string
Help string
campi := make(map[string]interface{})
for _, elem := range elems {
if elem.DBName != "" {
- if strings.Contains(elem.Validation, "numeric_it") {
+ if elem.DBType == "int" || elem.DBType == "float" || strings.Contains(elem.Validation, "numeric_it") {
/* tolgo la formattazione */
- campi[elem.DBName] = strings.ReplaceAll(elem.Value, ".", "")
- campi[elem.DBName] = strings.ReplaceAll(campi[elem.DBName].(string), ",", ".")
+ str := strings.ReplaceAll(elem.Value, ".", "")
+ str = strings.ReplaceAll(str, ",", ".")
+ if elem.DBType == "float" || strings.Contains(elem.Validation, "numeric_it=float") {
+ v, _ := strconv.ParseFloat(str, 64)
+ campi[elem.DBName] = v
+ } else {
+ v, _ := strconv.ParseInt(str, 10, 0)
+ campi[elem.DBName] = v
+ }
} else if strings.Contains(elem.Validation, "mydate") {
/* metto la data in formato sql */
if elem.Value == "" {
}
}
} else {
- campi[elem.DBName] = elem.Value
+ if elem.DBType == "bool" {
+ if elem.Value == "on" {
+ campi[elem.DBName] = true
+ } else {
+ b, err := strconv.ParseBool(elem.Value)
+ if err != nil {
+ campi[elem.DBName] = b
+ } else {
+ fmt.Println(err)
+ }
+ }
+ } else {
+ campi[elem.DBName] = elem.Value
+ }
}
}
}