308 | 308 |
|
309 | 309 |
// IsLongitude is the validation function for validating if the field's value is a valid longitude coordinate.
|
310 | 310 |
func isLongitude(fl FieldLevel) bool {
|
311 | |
return longitudeRegex.MatchString(fl.Field().String())
|
|
311 |
field := fl.Field()
|
|
312 |
|
|
313 |
var v string
|
|
314 |
switch field.Kind() {
|
|
315 |
case reflect.String:
|
|
316 |
v = field.String()
|
|
317 |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
318 |
v = strconv.FormatInt(field.Int(), 10)
|
|
319 |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
|
320 |
v = strconv.FormatUint(field.Uint(), 10)
|
|
321 |
case reflect.Float32:
|
|
322 |
v = strconv.FormatFloat(field.Float(), 'f', -1, 32)
|
|
323 |
case reflect.Float64:
|
|
324 |
v = strconv.FormatFloat(field.Float(), 'f', -1, 64)
|
|
325 |
default:
|
|
326 |
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
|
|
327 |
}
|
|
328 |
|
|
329 |
return longitudeRegex.MatchString(v)
|
312 | 330 |
}
|
313 | 331 |
|
314 | 332 |
// IsLatitude is the validation function for validating if the field's value is a valid latitude coordinate.
|
315 | 333 |
func isLatitude(fl FieldLevel) bool {
|
316 | |
return latitudeRegex.MatchString(fl.Field().String())
|
|
334 |
field := fl.Field()
|
|
335 |
|
|
336 |
var v string
|
|
337 |
switch field.Kind() {
|
|
338 |
case reflect.String:
|
|
339 |
v = field.String()
|
|
340 |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
341 |
v = strconv.FormatInt(field.Int(), 10)
|
|
342 |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
|
343 |
v = strconv.FormatUint(field.Uint(), 10)
|
|
344 |
case reflect.Float32:
|
|
345 |
v = strconv.FormatFloat(field.Float(), 'f', -1, 32)
|
|
346 |
case reflect.Float64:
|
|
347 |
v = strconv.FormatFloat(field.Float(), 'f', -1, 64)
|
|
348 |
default:
|
|
349 |
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
|
|
350 |
}
|
|
351 |
|
|
352 |
return latitudeRegex.MatchString(v)
|
317 | 353 |
}
|
318 | 354 |
|
319 | 355 |
// IsDataURI is the validation function for validating if the field's value is a valid data URI.
|