1249 | 1249 |
// IsTCP4AddrResolvable is the validation function for validating if the field's value is a resolvable tcp4 address.
|
1250 | 1250 |
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
|
1251 | 1251 |
func IsTCP4AddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
|
|
1252 |
|
|
1253 |
val := field.String()
|
|
1254 |
|
|
1255 |
if idx := strings.LastIndex(val, ":"); idx != -1 {
|
|
1256 |
val = val[0:idx]
|
|
1257 |
}
|
|
1258 |
|
|
1259 |
if !IsIPv4(v, topStruct, currentStructOrField, reflect.ValueOf(val), fieldType, fieldKind, param) {
|
|
1260 |
return false
|
|
1261 |
}
|
|
1262 |
|
1252 | 1263 |
_, err := net.ResolveTCPAddr("tcp4", field.String())
|
1253 | 1264 |
return err == nil
|
1254 | 1265 |
}
|
|
1256 | 1267 |
// IsTCP6AddrResolvable is the validation function for validating if the field's value is a resolvable tcp6 address.
|
1257 | 1268 |
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
|
1258 | 1269 |
func IsTCP6AddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
|
|
1270 |
|
|
1271 |
val := field.String()
|
|
1272 |
|
|
1273 |
if idx := strings.LastIndex(val, ":"); idx != -1 {
|
|
1274 |
if idx != 0 && val[idx-1:idx] == "]" {
|
|
1275 |
val = val[1 : idx-1]
|
|
1276 |
}
|
|
1277 |
}
|
|
1278 |
|
|
1279 |
if !IsIPv6(v, topStruct, currentStructOrField, reflect.ValueOf(val), fieldType, fieldKind, param) {
|
|
1280 |
return false
|
|
1281 |
}
|
|
1282 |
|
1259 | 1283 |
_, err := net.ResolveTCPAddr("tcp6", field.String())
|
1260 | 1284 |
return err == nil
|
1261 | 1285 |
}
|
|
1263 | 1287 |
// IsTCPAddrResolvable is the validation function for validating if the field's value is a resolvable tcp address.
|
1264 | 1288 |
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
|
1265 | 1289 |
func IsTCPAddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
|
|
1290 |
|
|
1291 |
// if string before the post is blank then invalid
|
|
1292 |
|
1266 | 1293 |
_, err := net.ResolveTCPAddr("tcp", field.String())
|
1267 | 1294 |
return err == nil
|
1268 | 1295 |
}
|
|
1291 | 1318 |
// IsIP4AddrResolvable is the validation function for validating if the field's value is a resolvable ip4 address.
|
1292 | 1319 |
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
|
1293 | 1320 |
func IsIP4AddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
|
|
1321 |
|
|
1322 |
if !IsIPv4(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) {
|
|
1323 |
return false
|
|
1324 |
}
|
|
1325 |
|
1294 | 1326 |
_, err := net.ResolveIPAddr("ip4", field.String())
|
1295 | 1327 |
return err == nil
|
1296 | 1328 |
}
|
|
1298 | 1330 |
// IsIP6AddrResolvable is the validation function for validating if the field's value is a resolvable ip6 address.
|
1299 | 1331 |
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
|
1300 | 1332 |
func IsIP6AddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
|
|
1333 |
|
|
1334 |
if !IsIPv6(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) {
|
|
1335 |
return false
|
|
1336 |
}
|
|
1337 |
|
1301 | 1338 |
_, err := net.ResolveIPAddr("ip6", field.String())
|
1302 | 1339 |
return err == nil
|
1303 | 1340 |
}
|
|
1305 | 1342 |
// IsIPAddrResolvable is the validation function for validating if the field's value is a resolvable ip address.
|
1306 | 1343 |
// NOTE: This is exposed for use within your own custom functions and not intended to be called directly.
|
1307 | 1344 |
func IsIPAddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
|
|
1345 |
|
|
1346 |
if !IsIP(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) {
|
|
1347 |
return false
|
|
1348 |
}
|
|
1349 |
|
1308 | 1350 |
_, err := net.ResolveIPAddr("ip", field.String())
|
1309 | 1351 |
return err == nil
|
1310 | 1352 |
}
|