func convertJsonValueToProperties(k string, v interface{}) []datastore.Property { propertyList := make([]datastore.Property, 0) switch v.(type) { case string: p := datastore.Property{Name: k} s := v.(string) if strings.HasPrefix(s, "[]") { p.Value = []byte(strings.TrimPrefix(s, "[]")) p.NoIndex = true propertyList = append(propertyList, p) } else { if dt, err := wcg.ParseDateTime(fmt.Sprintf("%s", v)); err == nil { p.Value = dt propertyList = append(propertyList, p) } else if d, err := wcg.ParseDate(fmt.Sprintf("%s", v)); err == nil { p.Value = d propertyList = append(propertyList, p) } else { p.Value = s propertyList = append(propertyList, p) } } case float64: str := []byte(fmt.Sprintf("%f", v)) if _float_re.Match(str) { // should be int. propertyList = append(propertyList, datastore.Property{ Name: k, Value: int64(v.(float64)), }) } else { propertyList = append(propertyList, datastore.Property{ Name: k, Value: v, }) } case bool: propertyList = append(propertyList, datastore.Property{ Name: k, Value: v, }) case []interface{}: for _, v1 := range v.([]interface{}) { propertyList = append(propertyList, datastore.Property{ Name: k, Value: v1, Multiple: true, }) } } return propertyList }
func (ovt *FormValidationTarget) GetFieldValue(field string) interface{} { values := ovt.values[field] typed := ovt.fieldTypes[field] if values != nil { if len(values) > 0 { switch typed { case fieldTypeBool: return values[0] == "true" || values[0] == "1" case fieldTypeInt: v, _ := strconv.Atoi(values[0]) return v case fieldTypeDate: v, e := wcg.ParseDate(values[0]) if e != nil { return nil } else { return v } case fieldTypeDateTime: v, e := wcg.ParseDateTime(values[0]) if e != nil { return nil } else { return v } default: // string return values[0] } } else { switch typed { case fieldTypeBool: return false case fieldTypeInt: return 0 default: // string return "" } } } else { return nil } }